2015-04-21 56 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()        
     });