Tuesday, January 8, 2013

Unable to update the EntitySet - because it has a DefiningQuery and no element exists in the element to support the current operation.

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

This error is raised while using Entity Framework.
While trying to save and persist db changes it raise this error. This error happens only in particular save and not every other places. The save operation raising this error is most probably an insert or a delete operation; like or example in my case:

db.Classrooms.Add(classroom);
db.SaveChanges();

Cause:
Eventhought the error message is a bit cryptic, the cause of the issue is simpler. The reason for this error is because the Primary key for the table is not set.

Solution:
Set the Primary key for the table and update the Entity Model (edmx file). This should clear the "Unable to update the EntitySet - because it has a DefiningQuery and no element exists in the element to support the current operation." exception.

No comments:

Post a Comment