Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element [duplicate]

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?

like image 807
Elad Benda Avatar asked Mar 10 '13 13:03

Elad Benda


3 Answers

My many-to-many mapping table was missing PK

added, and the issue is solved.

like image 151
Elad Benda Avatar answered Nov 16 '22 21:11

Elad Benda


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.

like image 24
Biki Avatar answered Nov 16 '22 21:11

Biki


If your view is updatable you can simply remove the element from the EntitySet definition for your view inside of the StorageModel section of your .edmx, and the normal update processing will work as with any other table.

This is the case for me. Simply removing resulted in another error. I followed the steps of this post except the last one. For your convenience, I copied the 4 steps from the post that I followed to solve the problem as following:

  1. Right click on the edmx file, select Open with, XML editor
  2. Locate the entity in the edmx:StorageModels element
  3. Remove the DefiningQuery entirely
  4. Rename the store:Schema="dbo" to Schema="dbo" (otherwise, the code will generate an error saying the name is invalid)
like image 28
kavitha Reddy Avatar answered Nov 16 '22 23:11

kavitha Reddy