Reputation: 685
First of all, my question is based on the answer that was given here.
I have a table where I didn't create a Primary Key. This table is used for logging purposes. While adding a new record to this table using EntityFramework (v6.0) I get the following error:
An exception of type 'System.Data.Entity.Infrastructure.DbUpdateException' occurred in EntityFramework.dll but was not handled in user code Additional information: Unable to update the EntitySet 'Status' because it has a DefiningQuery and no element exists in the element to support the current operation.
After some searches I found out that this error occurs because my table does not have a Primary Key. I know I can fix this error by adding a Primary Key to my table. But I want to know why.
Question: If it is not necessary for my design to use a Primary Key in my table, why isn't it possible for the EntityFramework to work with this?
Upvotes: 0
Views: 124
Reputation: 151586
why isn't it possible for EntityFramework to work with tables without primary keys?
That was a design decision. Entity Framework doesn't want to do updates when the uniqueness of a row cannot be determined.
They could have decided to support it, for example by adding where oldcolN=oldvalN
for all columns, but that could still potentially update more rows than intended.
Upvotes: 4