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.
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.
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.
ReplyDeleteYou are awesome! Thanks for the help. Worked like a charm.
ReplyDeleteIt worked just perfect !!!
ReplyDeleteThanks for update
ReplyDeleteThanks for that, EF is sensitive!!
ReplyDeleteThank you very much..
ReplyDeleteVery Helpful Thanks.
Thanks a bunch!
ReplyDeleteThanks 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!
ReplyDeleteThanks for post.
ReplyDeleteThanks a lot from obul.It is more helpful to me.
ReplyDeleteThank you very much..
ReplyDeleteIt is Very Helpful Thank you.
Gud one
ReplyDeleteIts absolutely fabulous the way u explained the whole Scenario.
ReplyDeleteAnd thanks for the Solution.
Thanks for the solution.
ReplyDeleteits fab the way u explained the entire scenario
Thanks for the Solution
ReplyDeleteGreat Job!
ReplyDeleteThanks
Tanxs George, it worked for me too,
ReplyDeleteAbhishek singh
Thanks.....It helped me lot.
ReplyDeleteThanks ...
ReplyDeletecool bro...i am glad i found your post...i missed the PK setting for 1 table and that ended up throwing error
ReplyDeleteHad 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
ReplyDeleteThanks a Lot.It is working fine...........
ReplyDelete