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

在使用MVC框架,向数据库中的表格插入一条数据时,出现以下问题:

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

注:上面*部分标示你要插入的数据库实体类名。

这个问题是在使用AdO.NET Entity Framework的时候,你使用的“XXX”这张表在数据库没有定义主键,只要设置了主键,就不会出现这个异常或这个错误了。

原文地址:https://www.cnblogs.com/akwwl/p/2671773.html