在实体框架中定义多对多关联

时间:2022-10-05 15:13:58

I have the following tables in my edmx :

我的edmx中有以下表格:

Errors

错误

Id, Description, solved, officeId, siteId

Sites

网站

id, location, name , officeId

Offices

办公室

officeId, officeName

the mapping between offices to sites are 1-to-many(offices can have many instances of sites).

办公室到站点之间的映射是1对多(办公室可以有许多站点实例)。

i want to create many-to-many association from Errors to Sites so i can access Sites properties directly. I always keeps error in mapping. can someone guide me how to do it right?

我想创建从错误到站点的多对多关联,以便我可以直接访问站点属性。我总是在映射中保持错误。有人可以指导我如何做对吗?

thanks in advance

提前致谢

1 个解决方案

#1


0  

You don't need to ad foreign key properties like officeId in Erros table in the edmx. Instead of adding those add associations among entities(Right click on your entity and choose addnew-> associatoin ). When you are adding associations you can define the relationship (one to many,may to many ...).

您不需要在edmx中的Erros表中添加officeId等外键属性。而不是在实体之间添加那些添加关联(右键单击您的实体并选择addnew-> associatoin)。添加关联时,您可以定义关系(一对多,可以多对......)。

#1


0  

You don't need to ad foreign key properties like officeId in Erros table in the edmx. Instead of adding those add associations among entities(Right click on your entity and choose addnew-> associatoin ). When you are adding associations you can define the relationship (one to many,may to many ...).

您不需要在edmx中的Erros表中添加officeId等外键属性。而不是在实体之间添加那些添加关联(右键单击您的实体并选择addnew-> associatoin)。添加关联时,您可以定义关系(一对多,可以多对......)。