Unable to update the EntitySet '...' because it has a DefiningQuery

asp.net-mvc c# entity-framework

Question

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();
1
2
1/17/2014 8:03:45 AM

Accepted Answer

Update your database, set pair of foreign key to tables in m2m table as primary key. Then update your model to database.

6
9/7/2012 11:01:49 AM

Popular Answer

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.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow