14

我的 linq 语句有什么问题,我做错了什么?

if (this.selectLBU.HtUsers.Any())
{
    reportRowItems = (from r in reportRowItems
                      from bu in r.User.HtBusinessUnits
                      where bu.LocationBusinessUnitId == selectLBU.LocationBusinessUnitId).ToList();
4

1 回答 1

25

您需要添加 select 子句来告诉您需要从查询中获得哪些数据。这篇msdn 文章描述了基本的查询操作和结构。

 reportRowItems = (from r in reportRowItems
                   from bu in r.User.HtBusinessUnits
                   where bu.LocationBusinessUnitId == selectLBU.LocationBusinessUnitId 
                   select r 
                  ).ToList();

要获得两个表的组合,您可以使用投影。

reportRowItems = (from r in reportRowItems
                   from bu in r.User.HtBusinessUnits
                   where bu.LocationBusinessUnitId == selectLBU.LocationBusinessUnitId 
                   select new {r.AttributeName1, r.AttributeName2, bu.AttributeName1}
                  ).ToList();
于 2012-11-21T08:50:22.780 回答