Pregunta

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?

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top