C# 查询主体必须以 select 子句或 group 子句结尾,为什么会出现错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13489436/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
A query body must end with a select clause or a group clause why is here an error?
提问by
What is wrong with my linq statement, what am I doing wrong?
我的 linq 语句有什么问题,我做错了什么?
if (this.selectLBU.HtUsers.Any())
{
reportRowItems = (from r in reportRowItems
from bu in r.User.HtBusinessUnits
where bu.LocationBusinessUnitId == selectLBU.LocationBusinessUnitId).ToList();
采纳答案by Adil
You need to add select clause to tell what data you require from query. This msdn articledescribes the basic query operation and structure.
您需要添加 select 子句来告诉您从查询中需要哪些数据。这篇msdn 文章描述了基本的查询操作和结构。
reportRowItems = (from r in reportRowItems
from bu in r.User.HtBusinessUnits
where bu.LocationBusinessUnitId == selectLBU.LocationBusinessUnitId
select r
).ToList();
To get combination of both tables you can use projection.
要获得两个表的组合,您可以使用投影。
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();

