Entity Framework issue on SaveChnages() of context

Vaibhav Bhapkar
2 min readApr 3, 2020

--

Recently while working with entity framework I faced this issue while updating the value of one of the tables in entity framework while I am allowed to use a select query on the same table,

Issue:

Unable to update the EntitySet ‘TableName’ because it has a DefiningQuery and no <UpdateFunction> element exists in the <ModificationFunctionMapping> element to support the current operation.

Reason:

After going through some of the resources I got to know there are different reasons because which you might face this problem those are listed below,

- An entity set is mapped from the database view

- Database table doesn’t have a primary key

The table doesn’t have the primary key treated as a view during the entity framework. The entity framework uses a class to define table/views and properties are used to refer to table/view columns. As we know insert and update are not allowed with only select is allowed.

Solution:

1) Define the primary key for your table which will start considering it as a table instead of view as mentioned earlier but for some cases, you might already have a primary key for your table then you should follow another solution.

2) Make the changes in edmx file manually,

- Locate edmx file in the project

- Right-click on edmx file -> Open with -> XML editor

- Search DefiningQuery tag in your file -> Remove that tag entirely

- Change store: Schema=” Database name” to Schema=” Database name”

- Save the changes of edmx file.

After doing this you are allowed to insert or update the value in a table using EF.

Thank You, See you in the next article !!

--

--

Vaibhav Bhapkar
Vaibhav Bhapkar

Written by Vaibhav Bhapkar

Technical Speaker | Computer Engineer | Full Stack Web Developer | ML Enthusiast | * Knowledge Shared = Knowledge² *

No responses yet