简体   繁体   English

具有稀疏表的实体框架

[英]Entity Framework with sparse tables

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 ? 如何使用实体框架封装此行为?

What you've illustrated is not a sparse table, its an Entity-Attribute-Value (EAV) table. 您所说明的不是一个稀疏表,而是一个Entity-Attribute-Value(EAV)表。 Entity Framework does not support EAV modeling, and it's probably just as well as it can lead to major performance issues . 实体框架不支持EAV建模,它可能会导致主要的性能问题

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. 有了Entity Framework的工作方式,除了最琐碎的应用程序之外,您都可以亲吻第三范式再见。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM