[英]EntityFramework Many to Many
Since upgrading to EF 6.1.3 I am unable to save anything to the DB. 自从升级到EF 6.1.3之后,我无法将任何内容保存到数据库。
I get an error: 我收到一个错误:
"Unable to update the EntitySet 'ProjectTask' because it has a DefiningQuery and no element exists in the element to support the current operation."
“无法更新EntitySet'ProjectTask',因为它具有DefiningQuery并且该元素中不存在任何元素来支持当前操作。”
The Tables define a many to many relationship: 这些表定义了多对多关系:
with all foreign keys defined. 定义了所有外键。 Pretty standard.
很标准。
Some posts indicated that the joining table ProjectTask
must have a primary key defined. 一些帖子指出,
ProjectTask
表ProjectTask
必须定义一个主键。 But, if I do that EF creates the ProjectTask
class in the data model which is not good. 但是,如果我这样做,EF就会在数据模型中创建
ProjectTask
类,这不好。
As a few people mentioned. 正如少数人所提到的。 Creating a composite key on ProjectTask table was the solution.
解决方案是在ProjectTask表上创建复合键。
ALTER TABLE dbo.ProjectTask
ADD CONSTRAINT ProjectTask_ProjectId_TaskId UNIQUE (ProjectId, TaskId)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.