簡體   English   中英

具有聯接和where子句的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();

看起來您正在將查詢理解語法與方法調用語法混合在一起。 嘗試更換.Wherewhere

您的查詢中有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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM