本文介绍了实体框架复合键(具有有效负载的多对多关系)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的数据库表:

一个人可能是许多团队的成员.一个团队可能有很多成员.每个人在团队中可能都有一个职位(认为是职务).

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.

我尝试使用ADO.NET实体框架进行设置并出现错误:

I've tried to set this up with ADO.NET Entity Framework and get errors:

我的 Membership 实体的主键是两个外键的复合键.我认为这就是问题所在.

The primary key of my Membership entity is a compound key of two foreign keys. I think that's the problem.

我必须做些什么?

推荐答案

如果您在既是主键又是外键的属性上使用独立的关联,则会发生这种情况. EFv4引入了外键关联(此处描述了差异),然后在实体.定义了引用约束后,请在映射详细信息"窗口中删除独立关联的映射.

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.

这篇关于实体框架复合键(具有有效负载的多对多关系)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 15:11