【发布时间】:2018-11-17 01:26:54
【问题描述】:
我有一个多对多关系表,我试图在表中显示报告列表。
我的桌子是这样的:
报告表:
Id| ReportName |
1 | report 1 |
2 | report 2 |
3 | report 3 |
报告类别表:
Id| Name |
1 | General |
2 | Specific |
ReportMapping 连接表:
Id| ReportId | CategoryId |
1 | 1 | 1 |
2 | 1 | 2 |
3 | 2 | 1 |
4 | 2 | 2 |
在此示例中,报告可以有多个类别,它只有 2 个,但可能还有更多,比如 1 个报告可以有 5 个类别,例如 General、Specific、Test2、Test3 和 Test4
我想在我的 .net 核心应用程序的表格/列表上显示一种格式,类似于:
ReportId| Report Name | Report Categories
1 | report 1 | General, Specific
2 | report 2 | General, Specific
我无法让它在 sql server 和 EF core linq 中工作。关于如何开始的任何指示?到目前为止,我能够将表格连接在一起,但不知道如何将我的结果连接到一行中以用于具有多个类别的报告。我得到的是下面的东西,而不是上面例子中我想要的结果:
ReportId | Report Name | Report Categories
1 | report 1 | General
1 | report 1 | Specific
2 | report 2 | General
2 | report 2 | Specific
任何帮助将不胜感激,谢谢!
【问题讨论】:
标签: sql-server linq asp.net-core entity-framework-core