Friday, July 26, 2013

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

Tied to debug my unit [TestMethod] in a unit test project through Test Explorer in Visual Studio 2012, then it tried to save the entity changes in database through a DbContext and it throw the folowing error message: 'Unable to update the EntitySet 'EntityName' because it has a DefiningQuery and no element exists in the element to support the current operation.'

In my case the problem was incorrect Entity Key setting on my entity in EF Model plus forgetting to set primary key in DB table. After setting primary key for the table which entity pointing too, I needed to update the model and open the EF model and manualy set Entity Key for primary key related member in the entity and clearing Entity Key setting for unnecessary entity members. Then rebuild, it worked. The reason was EF created a compound key made of all non nullable entity members which I had to reset them all.

It was my case but there are other possibilities for this error which already discussed if you search on Internet (Google or bing it)
Share/Bookmark

No comments: