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

I am trying to enter a new value in my database table row using Entity Framework in my asp.net MVC application, but getting this error

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

How can I solve it, any suggestions or help? thanks

Asked by:- Vinnu
: 15286 At:- 10/18/2017 3:25:35 PM
asp.net entity framework C# Unable to update the EntitySet

2 Answers
profileImage Answered by:- pika

You need to have Primary key in your table in which you are saving details, this error occurs as when EF mapping is done with a table which doesnot have Primary key, it is considered as a view & views being logical enity, cant be updated.

So adding PK in your table would work.

At:- 10/19/2017 11:02:38 AM
thanks 0
By : Vinnu - at :- 3/16/2018 12:12:40 PM

profileImage Answered by:- manish

I was getting the same error as described in question, in the below code and solved it with the help of @pika's answer

               Student_Marks stuDentMarks = new Student_Marks();
                stuDentMarks.Student_Id = int.Parse(model.Student_Id);
                stuDentMarks.Marks = int.Parse(model.stuDentMarks);

Solution: I rechecked Table Student_marks in Database and Primary Key was not set in the table , I set the primary key and above problem was resolved

At:- 3/16/2018 12:03:24 PM

Login/Register to answer
Register directly by posting answer/details

Full Name *

Email *

By posting your answer you agree on privacy policy & terms of use