簡體   English   中英

LinQ錯誤linq關節類型推斷無法調用“ join”錯誤

[英]LinQ Error linq joint type inference failed to call 'join' error

我是實體框架的新手,並且嘗試在兩個實體上使用join子句,如下所示。

var alertlist = from elogAlert  in yangkeeDBEntity.Yang_Kee_Logistics_Pte_Ltd_ELog_Tablet_Alert
                        where elogAlert.No_ != null
                        join elogAlertDetail in  yangkeeDBEntity. Yang_Kee_Logistics_Pte_Ltd_ELog_Tablet_Alert_Details
                        on elogAlert.No_ == elogAlertDetail.AlertID



                        where elogalertdetail.employee_id == driverid
                        select new
                        {
                            elogalertdetail.employee_id,
                            elogalertdetail.alert_id,
                            elogalertdetail.no_,
                            elogalertdetail.status,
                            elogalertdetail.created_by,
                            elogalertdetail.date_created,



                        };

您好,從以上代碼中,我收到兩個錯誤消息:

'Error  1   The name 'elogAlertDetail' is not in scope on the left side of 'equals'.  Consider swapping the expressions on either side of 'equals'.' and 'linq joint type inference failed to call 'join' error  '

當前,這兩個表沒有任何數據。 如果有人可以幫助我解決這種情況,我會很高興

與Linq一起加入時,不能使用== 您需要使用equals

請注意,它不是方法 .Equals(..)而是關鍵字

from elogAlert  in yangkeeDBEntity.Yang_Kee_Logistics_Pte_Ltd_ELog_Tablet_Alert
join elogAlertDetail in  yangkeeDBEntity.Yang_Kee_Logistics_Pte_Ltd_ELog_Tablet_Alert_Details

on elogAlert.No_ equals elogAlertDetail.AlertID //this line has equals instead of ==

                        where elogAlert.No_ != null
                        where elogalertdetail.employee_id == driverid
                        select new
                        {
                            elogalertdetail.employee_id,
                            elogalertdetail.alert_id,
                            elogalertdetail.no_,
                            elogalertdetail.status,
                            elogalertdetail.created_by,
                            elogalertdetail.date_created,
                        };

查看有關Linq加入的文獻

您遇到的錯誤與聯接時等號操作數周圍的參數順序有關。

聯接表必須是等於的RHS,並且LHS必須在要聯接的行中。

在這種情況下, yangkeeDBEntity不在elogAlert行中

CF MSDN中的示例

from c in categories 
        join p in products on c equals p.Category into ps 
        from p in ps 
        select new { Category = c, p.ProductName }; 

c在您要加入的行中, p.category在您要加入的表中

另外,您還需要使用單詞equals not == ,如上所述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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