X-45454545 X- [英] Edmx need Primary_Key?
问题描述
它的一个问题当在.net中创建Edmx时,在创建DataBase的Edmx时,只有那些表和视图被添加到谁拥有一个主键。
这个问题很容易解决,只是在列主键表或视图,但我没有得到实际的理由为什么必要?
任何人都可以解释背后的原因?
Its a problem While Creating Edmx in .net that on creating Edmx of DataBase only those Tables and views are added who had a primary key.
This problem resolved easily but just making a column primary key in Table or View but i didn't got the actual reason why it is necessary??
Can anyone please explain the reason behind it?
推荐答案
实体框架需要一个主键,才能在特定数据集中正确识别一条数据。它归结为如何在内部查找实体,并为您提供最佳性能。
Entity Framework needs a primary key to properly identify a piece of data as unique in a particular set of data. It comes down to how it looks up entities internally and giving you the best performance possible.
例如,Entity Framework的一个功能是更改跟踪,它在一系列集合中保留了添加,删除,修改和不变实体的集合,定义为 Dictionary< EntityKey,EntityEntry>
。为了能够有效地处理这些集合,它需要一个关键,以及时地对这些集合执行必要的CRUD操作,因此需要这个密钥。
For example, one of the features of Entity Framework is Change Tracking, which keeps a collection of Added, Deleted, Modified, and Unchanged entities in a series of collections defined as Dictionary<EntityKey, EntityEntry>
. To be able to effectively handle those collections, it needs a key to perform the necessary CRUD operations to those collections in a timely manner, and as a result, it needs that key.
更新:
还有一个无钥匙对象的集合,但它被定义为 Dictionary< object ,EntityEntry>
,因为关键字将需要被转换(或者如果键是一个值类型,则可以取消装箱),因此可以查找这些查询的可怕性能。
There is also a collection for keyless objects as well, but it's defined as Dictionary<object, EntityEntry>
which has horrible performance for lookups as the key would need to be cast (or unboxed if the key is a value type) for it to be usable.
这篇关于X-45454545 X-的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!