Domanda

My data table is sparse, therefore the data is stored as such:

RowId  |  Field  |  Value
  1    ,"Field1",    1.00
  1    ,"Field2",    2.00
  1    ,"Field4",    4.00
  2    ,"Field1",    1.00
  2    ,"Field3",    3.00

And several rows in the DB should be handled as a single object. for example:

Model obj=new Model(1);//where 1 refers to the RowId
obj.Field1=1;//should update the relevant row
obj.Field2=0;//should delete the relevant row (assuming 0 is the default value)
obj.Field3=3;//should create a new row

How can I use entity framework to encapsulate this behavior ?

È stato utile?

Soluzione

What you've illustrated is not a sparse table, its an Entity-Attribute-Value (EAV) table. Entity Framework does not support EAV modeling, and it's probably just as well as it can lead to major performance issues.

If your attributes are not dynamic then you can model your data in a more conventional manner and use Sparse Columns, though they have their own pros and cons.

Given the way that Entity Framework works, for anything but the most trivial of applications you can kiss 3rd Normal Form goodbye.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top