How to store double[] array to database with Entity Framework Code-First approach

后端 未结 6 788
忘掉有多难
忘掉有多难 2020-12-25 11:58

How can I store an array of doubles to database using Entity Framework Code-First with no impact on the existing code and architecture design?

I\'ve looked at Data A

6条回答
  •  无人及你
    2020-12-25 12:28

    You can do a thing like this :

        [NotMapped]
        public double[] Data
        {
            get
            {
                string[] tab = this.InternalData.Split(',');
                return new double[] { double.Parse(tab[0]), double.Parse(tab[1]) };
            }
            set
            {
                this.InternalData = string.Format("{0},{1}", value[0], value[1]);
            }
        }
    
        [EditorBrowsable(EditorBrowsableState.Never)]
        public string InternalData { get; set; }
    

提交回复
热议问题