Unable to update the EntitySet '...' because it has a DefiningQuery
Solution 1
Update your database, set pair of foreign key to tables in m2m table as primary key. Then update your model to database.
Solution 2
Please check, if all ID fields in tblAdminUserRole
have been set as Primary Key in your SQL database. Then update your model.
If Entity Framework can't figure out the primary key, it will generate a SELECT
statement but it won't be able to create the according INSERT
, UPDATE
and DELETE
statements.
rhughes
Entering the foray of mobile games: http://www.cupofcoffeegames.com/ https://www.facebook.com/cupofcoffeegames
Updated on June 30, 2022Comments
-
rhughes almost 2 years
I am using MVC 4 and C# 4.5 with EntityFramework 4.
I have setup a simple Many to Many table:
tblAdminUser -> tblAdminUserRole <- tblAdminRole
When I try to add a role to the admin user, I get the following error:
"Unable to update the EntitySet 'tblAdminUserRole' because it has a DefiningQuery and no element exists in the element to support the current operation."
The code I am using is:
this.Role = new tblAdminRole() { Name = "__role__", }; context.tblAdminRoles.Add(this.Role); context.SaveChanges(); this.AdminUser.tblAdminRoles.Add(this.Role); context.SaveChanges();
-
OneWorld over 11 yearsYou need to set a compound key. In SQLite you do it like that: stackoverflow.com/questions/734689/…