开发者

How to add an array to Entity Model in VS?

I want so store a histogram of an image in a database. In the program the histogram is represented as an array of doubles (exactly 64)

What's is the best way to add it to entity m开发者_运维知识库odel? (anything better than adding complex type with multiple double values?)

P.S. If it matters - I plan to generate my db from the entity model.


Create a separate entity 'Sample' with an Int Index and a double Value scalar property.

Add an association from Image to Sample: 1 to many.

That will give you a navigation property on image called Samples and you can do:-

image.Samples.OrderBy(s => s.Index).Select(s => s.Value).ToArray() to recover the array.

This structure allows you to change the value 64 later easily.

Edit To create the entities you can use Linq

   var values = histogram.Select((d,i) => new Sample(){Index =i, Value = d});
   var image = new Image(){ Samples = values };
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜