![](/img/trans.png)
[英]Where clause in complex linq query giving the following error “A query body must end with a select clause or a group clause linq”
[英]Linq query with a join and a where clause giving an error
我對此Linq查詢做錯什么?
sql語句是:
SELECT
*
FROM
ReportGroups rg INNER JOIN ReportDefinitions rd on rg.ReportGroupID = rd.ReportGroupID
WHERE
rd.ReportGroupID = 5
LINQ:
var query = from rg in ReportGroups
join rd in ReportDefinitions on rg.ReportGroupID equals rd.ReportGroupID
.Where rd.ReportGroupID equals 5
select new
{
rg.ReportGroupName,
rd.ReportName
};
query.Dump();
看起來您正在將查詢理解語法與方法調用語法混合在一起。 嘗試更換.Where
有where
。
您的查詢中有2個錯誤。
首先使用where
代替.Where
。
其次,在where
子句中不要使用equals
use ==
, equals
僅用於joins
像這樣:
var query = from rg in ReportGroups
join rd in ReportDefinitions on rg.ReportGroupID equals rd.ReportGroupID
where rd.ReportGroupID == 5 //updates here
select new
{
rg.ReportGroupName,
rd.ReportName
};
query.Dump();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.