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

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

    I know it is a bit expensive, but you could do this

    class Primitive
    {
        public int PrimitiveId { get; set; }
        public double Data { get; set; }
    
        [Required]
        public Reference ReferenceClass { get; set; }
    }
    
    // This is the class that requires an array of doubles
    class Reference
    {
        // Other EF stuff
    
        // EF-acceptable reference to an 'array' of doubles
        public virtual List Data { get; set; }
    }
    

    This will now map a single entity (here 'Reference') to a 'list' of your Primitive class. This is basically to allow the SQL database to be happy, and allow you to use your list of data appropriately.

    This may not suit your needs, but will be a way to make EF happy.

提交回复
热议问题