2010-06-23 259 views
1

的名單我有一個查詢:LINQ查詢返回列表

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是不是隻是返回ReportingViews的單一平面列表(作爲最後的查詢返回)類似的查詢循環來創建一個新的列表?

謝謝!

回答

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; 

+1

謝謝!不知道我能做到這一點,而不在每一點上的select語句。 – 2010-06-23 16:06:15