Reputation: 20648
I'm quite new to entity framework and I'm trying to use the join clause on two entities as follows.
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,
};
Hi from the above code I'm getting two errors saying
'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 '
Currently the two tables does not have any data. Ill be happy if anyone can help me with this situation
Upvotes: 1
Views: 2414
Reputation: 34248
The error you have relates to the order of arguments around the equals operand on join.
The joined table MUST be the RHS of the equals, and the LHS must be in the row you are joining to.
In this instance yangkeeDBEntity
is not in the elogAlert
row
CF the example in 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
is in the row you are joining from, p.category
is on the table you are joining to
in addition you also need to use the word equals
not ==
as mentioned above
Upvotes: 1
Reputation: 11277
you cant use ==
when joining with Linq. You need to use equals
.
Note that it is not the method .Equals(..)
but the keyword
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,
};
Look at the documentaion on Linq join
Upvotes: 4