2015-04-21 54 views
3
用我的實體框架,我的數據庫,並選擇和/或包含暴露這麼多的數據所以基本上我正在尋找這樣的查詢

如何選擇通過LINQ的(實體框架)選擇

var result = DbContext.products 
      .select(p=> new { 
      p.Id, 
      p.Name, 
      p.Notes 
      .select(n=> new { 
       n.date, 
       n.text 
          } 
      }); 

回答

5

你可以使用此代碼:

var result = DbContext.products 
     .select(p=> new { 
         Id = p.Id, 
         Name = p.Name, 
         SelectedNodes = p.Notes.select(n=> 
              new {n.date, n.text}).ToList()        
     });