简体   繁体   English

如何首先使用实体​​框架数据库维护表中的多重关系?

[英]How to maintain Multiple Relation In tables Using Entity Framework Database first?

I am using Entity Framework 5 (DB first).In my project I want to show data of two tables which don't have direct relation, In following condition Table A is master Table. 我正在使用Entity Framework 5(首先使用DB)。在我的项目中,我想显示两个没有直接关系的表的数据,在以下情况下,表A是主表。 Table A and B are in relationship, B and C ,B and D are in relationship I want to show data from A,C and D . 表A和B有关系,B和C有关系,B和D有关系我想显示来自A,C和D的数据。 I don't know how should I maintain this relation in way that help me to use ORM query in Razor view .So that I can Use only one main model of Table A to show relational tables data 我不知道如何维护这种关系,以帮助我在Razor视图中使用ORM查询。因此,我只能使用表A的一个主要模型来显示关系表数据

在此处输入图片说明

I would normalize your schema, changing TableB with relations columns for relations with TableA, for TableC and TableD, 我将规范化您的架构,将带有关系列的TableB更改为与TableA,TableC和TableD的关系,

TABLE B:
ID | fk_A | fk_C | fk_D
B1    A1     C1    null
B2    A1     C2    null
B3    A2     C3    null
B4    A2     null  D1
B5    A3     null  D2
B6    A3     null  D3

I don't know the nature of the relationship, but if B meaning is only to join A with other columns you could also have B3 and B4 in a single record like: B7 A2 C3 D1 我不知道这种关系的性质,但是如果B的含义只是将A与其他列连接在一起,那么您也可以在一条记录中包含B3和B4,例如:B7 A2 C3 D1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM