2013-10-03 88 views
0

希望通過在linq中嘗試向下三個級別嵌套組獲得幫助。試圖按對象返回多個組

基本上路徑會下降業務BusUnit1級

所以下企業有各種BusUnits下BusUnits有我想回到這個各種1級值

一個Json對象。

正如我在此刻有它我下到BusUnits

如下

var queryNestedData = (from r in DataItems 
         group r by r.Business into businesses 
         from businessUnits in 
         (from r in businesses 
         group r by r.Businessunit) 
         group businessUnits by businesses.Key).Select(tg => 
         new 
         { 
          Business = tg.Key, 
          BusinessUnits = tg.Select(tv => new { BusinessUnit = tv.Key }) 
        }); 

我怎樣才能到1級,以便返回的值呢?

+0

您嘗試'連接'在'LINQ'? –

回答

1

您可以指定相關對象以包含在查詢結果中。精確的片段依賴於您正在使用的LINQ提供程序。對於實體框架,它將是:

... from r in DataItems.Include(di => di.Business.Businessunit.Level1) ...