LINQ question (JOINs related)
Hi
I am having trouble converting a query that contains AND operator in JOIN into LINQ. For example, our sample query is
Code:
SELECT
e.name, a.city
FROM
Emp e INNER JOIN Address a ON e.id = a.emp_id AND e.country = a.country
WHERE
e.prof = 'doctor'
The main thing that is confusing me how to deal with the last AND clause.
Re: LINQ question (JOINs related)
Try this:
Code:
var query =
from e in Emp
join a in Address on new {f1 = e.id, f2 = e.country} equals new {f1 = a.emp_id, f2 = a.country} into temp
from t in temp.DefaultIfEmpty()
where t.prof = "doctor"
select new {t.name, t.city};
Re: LINQ question (JOINs related)
Quote:
Originally Posted by cilu
Try this:
Code:
var query =
from e in Emp
join a in Address on new {f1 = e.id, f2 = e.country} equals new {f1 = a.emp_id, f2 = a.country} into temp
from t in temp.DefaultIfEmpty()
where t.prof = "doctor"
select new {t.name, t.city};
I think that you converted it into LEFT OUTER JOIN. will try it shortly