[英]Linq query with a join and a where clause giving an error
What am i doing wrong with this Linq query? 我对此Linq查询做错什么?
The sql statement is : sql语句是:
SELECT
*
FROM
ReportGroups rg INNER JOIN ReportDefinitions rd on rg.ReportGroupID = rd.ReportGroupID
WHERE
rd.ReportGroupID = 5
LINQ: 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();
It looks like you're mixing query comprehension syntax with method call syntax. 看起来您正在将查询理解语法与方法调用语法混合在一起。 Try replacing
.Where
with where
. 尝试更换
.Where
有where
。
There are 2 mistakes in your query. 您的查询中有2个错误。
First of all use where
instead of .Where
. 首先使用
where
代替.Where
。
Secondly in the where
clause don't use equals
use ==
, equals
is used for joins
only 其次,在
where
子句中不要使用equals
use ==
, equals
仅用于joins
Like this: 像这样:
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.