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

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();

Answers


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


Need Your Help

PHP Transaction-like sql required?

php curl transactions

I used cURL to authenticate first then login via POST to a cms.

Loading symbol file for debugging cross-compiled VLC (mingw in Linux) project under windows environment (Cygwin)

debugging gdb cygwin mingw cross-compiling

I have encounter a problem using gdb to debug vlc.exe in windows environment. I follow the instruction on http://wiki.videolan.org/Win32Compile and successfully compiled and packaged VLC under linu...