简体   繁体   English

具有联接和where子句的Linq查询给出错误

[英]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 . 尝试更换.Wherewhere

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM