Unable to update the EntitySet because it has a DefiningQuery and no element exists in the element to support the current operation.

c# sql server entity framework 3 Comments

After integrating the new forum code, I added basic subscription support. When replying to a topic and opting to subscribe to notifications, the following exception would be thrown:

Unable to update the EntitySet 'ThreadSubscriptions' because it has a DefiningQuery and no element exists in the element to support the current operation.

I'd already checked the Entity model to ensure the relationships were set up correctly as a many to many, as one user may be subscribed to many threads, and any given thread can have many subscribed users, so I was a little perplexed as to where this was coming from.

After looking at the database table which links threads and users, I realized the problem was the table didn't have a unique key, only the relationships. After creating a primary key on the two columns in this table, and regenerating the Entity model, the exception disappeared and subscriptions are now working as expected.

It's always the little things...