Entity Framework Compound Key (Many-To-Many Relationship with a Payload)

杀马特。学长 韩版系。学妹 提交于 2019-12-14 04:27:15

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/5862352/entity-framework-compound-key-many-to-many-relationship-with-a-payload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!