This thing is driving me crazy, and the error is quite meaningless to me:
Unable to update the EntitySet 'TableB' because it has a DefiningQuery and no element exists in the element to support the current operation.
My tables are put like this:
TableA int idA (identity, primary key) ... TableB int idA (FK for TableA.idA) int val
TableB has no defined primary key in the SQL server. The Entity Framework has imported the table and the association and set both fields as key. But it will output that error when I try to do an insert into the table!
What's wrong??
Edit: As suggested by Alex, the solution was this:
- Right click on the edmx file, select Open with, XML editor
- Locate the entity in the edmx:StorageModels element
- Remove the DefiningQuery entirely
- Rename the store:Schema="dbo" to Schema="dbo" (otherwise, the code will generate an error saying the name is invalid)
- Remove the store:Name property
I left the key as it was, since it was OK to me that both the columns are part of the key.