Click to See Complete Forum and Search --> : LINQ question (JOINs related)


nabeelisnabeel
October 15th, 2008, 06:52 AM
Hi

I am having trouble converting a query that contains AND operator in JOIN into LINQ. For example, our sample query is


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.

cilu
October 15th, 2008, 08:01 AM
Try this:

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};

nabeelisnabeel
October 15th, 2008, 08:32 AM
Try this:

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