c# - LINQ 查询返回列表列表

标签 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,结果我得到一组 IQueryable。

我如何编写一个类似的查询,而不是只返回一个简单的 ReportingView 列表(如最后一个查询返回的那样),而不使用 foreach 循环来创建一个新列表?

谢谢!

最佳答案

类似于:

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;

?

关于c# - LINQ 查询返回列表列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3102326/

相关文章:

c# - MonoTouch - UIView.Animate 完成回调未在按钮 touchUpInside 委托(delegate)内调用

c# - 如何发送一个http basic auth post?

c# - 从集合中查找一组值

linq-to-sql - 工作单元设计模式

.net - Linq to SQL 创建表

c# - 是否可以用 C# 模拟 ms-access 的功能?

c# - Migratordotnet 创建初始迁移

c# - 如何通过辅助方法打印当前执行的方法名?

c# - LINQ 到实体 : Orderby statement involving extension method

c# - 将 Windows Phone 8 应用程序连接到远程 mysql 数据库