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

后端 未结 6 795
忘掉有多难
忘掉有多难 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:36

    Thank you all for your inputs, due to your help I was able to track down the best way to solve this. Which is:

     public string InternalData { get; set; }
     public double[] Data
     {
        get
        {
            return Array.ConvertAll(InternalData.Split(';'), Double.Parse);                
        }
        set
        {
            _data = value;
            InternalData = String.Join(";", _data.Select(p => p.ToString()).ToArray());
        }
     }
    

    Thanks to these stackoverflow posts: String to Doubles array and Array of Doubles to a String

提交回复
热议问题