如何存储双[]数组数据库实体框架code-First方法 [英] How to store double[] array to database with Entity Framework Code-First approach

查看:214
本文介绍了如何存储双[]数组数据库实体框架code-First方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何可以存储双打使用实体框架code-首先对现有的code和架构设计没有影响阵列数据库?

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?

我看着数据诠释和流利的API,我也考虑了双数组转换为字节的字符串和存储字节到数据库中它自己的专栏。

I've looked at Data Annotation and Fluent API, I've also considered converting the double array to a string of bytes and store that byte to the database in it own column.

我无法访问公共双[]数据{获得;组; } 财产流利的API,该错误信息,然后我得到的是:

I cannot access the public double[] Data { get; set; } property with Fluent API, the error message I then get is:

类型双[] 必须是一个非空的值类型才能使用   它作为参数'T'。

The type double[] must be a non-nullable value type in order to use it as parameter 'T'.

其中,数据存储成功存储在数据库中的类,这个类的关系。我只错过了数据列。

The class where Data is stored is successfully stored in the database, and the relationships to this class. I'm only missing the Data column.

推荐答案

感谢大家的投入,因为你的帮助,我能够追踪解决这一问题的最佳途径。那就是:

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());
    }
 }

由于这些计算器的帖子: 字符串数组双打并 双打数组为String

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

这篇关于如何存储双[]数组数据库实体框架code-First方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆