because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element
C#.NetEntity FrameworkC# Problem Overview
I'm using EF in my application.
I try to save\insert a new record to a mapping table
and get the following error:
Unable to update the EntitySet 'UsersLimitationToCountry' because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation.
Should I define it in the edmx myself? How?
C# Solutions
Solution 1 - C#
My many-to-many mapping table was missing PK
added, and the issue is solved.
Solution 2 - C#
Agreed with the accepted answer. Just providing the reason behind it...
When EF mapping is done with a table which does not have a primary key, it is treated as a view. Since views are logical entities, they can't be updated.
So either add the missing primary key to your table or consider them as a view & don't perform any update operation on them.
Solution 3 - C#
> If your view is updatable you can simply remove the
This is the case for me. Simply removing
- 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)
Solution 4 - C#
I came across this problem on an updatable view. Found this article solved my problem.
So the underlying table of my view does have primary key defined but EF does not know which columns are in the PK as the entity was built on the view. The trick here is to 'convince' EF that your view can be updated as a table. Steps are almost the same as mentioned by above answers:
- Right click on the edmx file, select Open with, XML editor
- Locate the entity in the edmx:StorageModels element
- Remove the
<DefiningQuery>
section entirely - Rename the store:Schema="dbo" to Schema="dbo"
- Change
store:Type="Views"
tostore:Type="Tables"
Solution 5 - C#
-
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"
toSchema="dbo"
(otherwise, the code will generate an error saying the name is invalid) These steps worked for me
Solution 6 - C#
My table didn't have primary key in sql table design. Added it and solved.
Solution 7 - C#
Make sure your foreign key tables do not have more than one column names that match the columns in your referring table; only primary key should match between your ref table with refereed table. 0..1 should have distinguished column name, develop naming convention for your columns that will ensure referring and refereed tables do not have more than one matching columns names. Courtesy of ALMwConsult.net
Solution 8 - C#
*Recheck your tables doesn't have PK :* just add Primary Key and then remove and re-add table to edmx then it should work
Solution 9 - C#
If you are not handling primary key in your table then this issue will definitely occur in MVC while updating and inserting record database
DbUpdate Exception was unhandled by user
Solution 10 - C#
Working on db first mvc application. The problem was i forget to define primary key for the table. Solved by adding primary key using alter command and updating the DAL(edmx)