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
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.
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);
context.AddToStudent_Marks(stuDentMarks);
context.SaveChanges();
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
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly