【发布时间】:2019-04-14 16:20:18
【问题描述】:
嗨。我有三个表,我正在尝试将它们分组和子组。
Table Sections
-------------
Id
SectionName
Table Categories
-------------
Id
CategoryName
SectionRefId
Table Records
-------------
Id
RecordName
CategoryRefId
我想要实现的是按 SectionName 对所有类别进行分组,并按 CategoryName 对所有记录进行分组,并使用 foreach 循环显示它们。
I tried this using Linkpad the result it not what i exptected </p>
var result = from doc in Categories
group doc by doc.SectionRefId into docSections
select new
{
Name = docSections.Key,
Group = from dl in Records
group dl by dl.CategoryRefId into dlRecords
select new
{
Name = dlRecords.Key,
GroupRecords = dlocation
}
};
enter code here
【问题讨论】:
-
你有相同的sql查询吗?
-
无 sql 查询,我试图仅使用 linq 来解决。尝试以下解决方案。
标签: c# entity-framework linq model-view-controller