Unable to update the EntitySet because it has a DefiningQuery and no <UpdateFunction> element

Posted by Harish Ranganathan on Geeks with Blogs See other posts from Geeks with Blogs or by Harish Ranganathan
Published on Mon, 31 May 2010 12:12:41 GMT Indexed on 2010/05/31 13:23 UTC
Read the original article Hit count: 2101

Filed under:

When working with ADO.NET Entity Data Model, its often common that we generate entity schema for more than a single table from our Database.  With Entity Model generation automated with Visual Studio support, it becomes even tempting to create and work entity models to achieve an object mapping relationship.

One of the errors that you might hit while trying to update an entity set either programmatically using context.SaveChanges or while using the automatic insert/update code generated by GridView etc., is “Unable to update the EntitySet <EntityName> because it has a DefiningQuery and no <UpdateFunction> element exists in the <ModificationFunctionMapping> element to support the current operation”

While the description is pretty lengthy, the immediate thing that would come to our mind is to open our the entity model generated code and see if you can update it accordingly.

However, the first thing to check if that, if the Entity Set is generated from a table, whether the Table defines a primary key.  Most of the times, we create tables with primary keys.  But some reference tables and tables which don’t have a primary key cannot be updated using the context of Entity and hence it would throw this error.  Unless it is a View, in which case, the default model is read-only, most of the times the above error occurs since there is no primary key defined in the table.

There are other reasons why this error could popup which I am not going into for the sake of simplicity of the post.  If you find something new, please feel free to share it in comments.

Hope this helps.

Cheers !!!

© Geeks with Blogs or respective owner