实体框架复合键(与有效负载的多对多关系)
我有这样的数据库表:
一个人可能是一个许多团队的成员。一个团队可能有很多成员。每个人在团队中都可能有一个职位(想想职称)。
我尝试使用 ADO.NET 实体框架进行设置并收到错误:
错误 3021:映射问题 从 ... 行开始的片段 表中的以下列 成员资格映射到多个 概念性的侧面属性: Membership.PersonId 映射到
和
错误 3021:映射问题 从 ... 行开始的片段 表中的以下列 成员资格映射到多个 概念性的侧面属性: Membership.TeamID 映射到
我的Membership 实体的主键是两个外键的复合键。我认为这就是问题所在。
我必须采取什么不同的做法?
I've got database tables like this:
A person may be a member of many teams. A team may have many members. Each person may have a position (think job title) within the team.
I've tried to set this up with ADO.NET Entity Framework and get errors:
Error 3021: Problem in mapping
fragments starting at line ... Each of
the following columns in table
Membership is mapped to multiple
conceptual side properties:
Membership.PersonId is mapped to
<MembershipPerson.Membership.PersonId,
MembershipPerson.Person.Id>
and
error 3021: Problem in mapping
fragments starting at line ... Each of
the following columns in table
Membership is mapped to multiple
conceptual side properties:
Membership.TeamID is mapped to
<MembershipTeam.Membership.TeamId,
MembershipTeam.Team.Id>
The primary key of my Membership entity is a compound key of two foreign keys. I think that's the problem.
What must I do differently?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您对既是主键又是外键的一部分的属性使用独立关联,就会发生这种情况。 EFv4 引入了外键关联(此处描述了差异< /a>) 并且一旦您在实体 您必须定义foreign关键关联。定义引用约束后,在映射详细信息窗口中删除独立关联的映射。
This happens if you use independent association on the property which is both part of primary key and foreign key. EFv4 introduced Foreign key associations (the difference is described here) and once you expose foreign key in the entity you must define foreign key association. After defining referential constraints delete mapping of independent association in Mapping details window.