Thursday, July 8, 2010

Unable to update the EntitySet 'MyEntity' because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation.

If you are using the ADO.NET Entity Framework and a Domain Service (I don’t think you have to be using a Domain Service to have this issue) and you get the error:

Unable to update the EntitySet 'MyEntity' because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation.

One common reason you get this is that the table you are trying to update doesn’t have a single primary key in the database. This then causes the Entity Framework to create a compound key of all the non-nullable columns.

To solve the issue, just create a primary key on the table and update your model. You will have to manually change the Entity Key property to False for all the properties that are not your primary key.

If you are not so lucky to have just forgot to create a primary on the database table, then you may check out this forum for more info on options. I was lucky, I just needed to add a primary key to my table. :) Good luck.