LINQ查询返回列表列表

时间:2010-06-23 14:05:19

标签: c# linq linq-to-sql

我有一个问题:

from m in dc.ReportingMonths
where m.Month.Value == month
select (from k in m.KPI_Actives
        where k.DateActive.Year == year
        select (from r in dc.ReportingViews
                where r.KPIID == k.KPIID select r)
       );

显然,因为它是嵌套的LINQ查询 - 每个返回一个IQueryable,我得到一组IQueryables作为结果。

如何在不使用foreach循环创建新列表的情况下编写类似的查询,而只返回ReportingView的单个平面列表(如上一个查询返回)?

谢谢!

1 个答案:

答案 0 :(得分:6)

类似的东西:

from m in dc.ReportingMonths where m.Month.Value == month
from k in m.KPI_Actives
where k.DateActive.Year == year
from r in dc.ReportingViews
where r.KPIID == k.KPIID
select r;