views:

19

answers:

1

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 model? (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.

A: 

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 };
Hightechrider
Thanks for the answer. I'm just concerned - how do I put data into entities? (for loop? :/). Having 100 images in my db would create 6400 records :/ and I want to store multiple histograms per image. Any ideas including binary data maybe?
kyrisu
I added some Linq to show you how you can create it. Why are you worrying about performance optimization for a proof of concept application? This will be plenty fast enough and gives greater flexibility to design your entities.
Hightechrider