I’m attempting to add data to a table and linq to entities throws an excpetion with:
Unable to update the EntitySet ‘XXXX’ because it has a DefiningQuery
and no element exists in the
element to support the current
operation.
The table I’m trying to add data has no primary key and if I add a column of int and set it as primary key, the problem goes away, but in a purist/OCD sense, this column is not necessary
UserTable UserGroup GroupTable
ID Name UserId GroupId ID Name
Does adding data to a DB table with Linq to Entities (EDMX) require that the table have a primary key?
You can manually edit the generated
.edmxfile, look for Error strings and correct them. It turns out that EF does need a primary key for every table (which is not a many-to-many relationship).More on tables without primary keys and why it is considered wrong to EF: http://www.i-think22.net/archives/2009/07/24/linq-to-sql-and-tables-with-no-primary-key/