Tuesday, October 27, 2009

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

ASP.NET MVC is the technology released from Microsoft long time back. But I didn’t get time to dig into it and research on it. Now, I need to learn it as my next project is in ASP.NET MVC. So, I thought to give a try and want to show all records in a table and insert a new record in a table. On the way, The above is the exception which blocked me to go proceed. I didn’t do any mistake and always the above exception come into picture when I try to create a new record in table.

So, frustrated and started research on the error and debugging. After a long research found the issue in the Entity framework. The whole thing is only because I forgot to add primary key to the table in the database. Once I added the primary key and reconstructed the edmx file with new changes, All works fine and record added to table in database. So, what is happening inside is, entity framework is looking for a key in each and every table [Primary key]. So, don’t forget to add a primary key to each and every table which you want to use in entity framework file [.edmx]. Otherwise you always see this exception when you try to insert or update a record.

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

Is this helpful? Follow me if you want to learn ASP.NET MVC framework. I started learning and will place all my experiences and problems I face in my blog. So, keep an eye on my blog for more updates.

22 comments:

  1. The confusing thing is that the entity framework claims to infer a key (all the columns... which in my case is what the key is) but still wont work unless you explicitly set the key in the database (SQL Server 2008 for me) and then update your framework accordingly. Very Helpful Thanks.

    ReplyDelete
  2. You are awesome! Thanks for the help. Worked like a charm.

    ReplyDelete
  3. It worked just perfect !!!

    ReplyDelete
  4. Thanks for that, EF is sensitive!!

    ReplyDelete
  5. Thank you very much..
    Very Helpful Thanks.

    ReplyDelete
  6. Thanks a ton. I created a very simple table model to test out custom role providers. My table was User with just userName and Password (no primary key). I was trying to keep it simple for testing reasons but I guess I kept it too simple. Thanks for posting!

    ReplyDelete
  7. Thanks a lot from obul.It is more helpful to me.

    ReplyDelete
  8. Thank you very much..
    It is Very Helpful Thank you.

    ReplyDelete
  9. Its absolutely fabulous the way u explained the whole Scenario.
    And thanks for the Solution.

    ReplyDelete
  10. Thanks for the solution.
    its fab the way u explained the entire scenario

    ReplyDelete
  11. Thanks for the Solution

    ReplyDelete
  12. Tanxs George, it worked for me too,
    Abhishek singh

    ReplyDelete
  13. Thanks.....It helped me lot.

    ReplyDelete
  14. cool bro...i am glad i found your post...i missed the PK setting for 1 table and that ended up throwing error

    ReplyDelete
  15. Had a single table with no primary key. Refused to believe that was the issue. Added the key and now it works - thanks for the post

    ReplyDelete
  16. Thanks a Lot.It is working fine...........

    ReplyDelete