Edmx need Primary_Key?

≯℡__Kan透↙ 提交于 2019-12-10 13:24:04

问题


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?


回答1:


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.

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.

Update:

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.



来源:https://stackoverflow.com/questions/20655212/edmx-need-primary-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!