|
-
October 15th, 2008, 06:52 AM
#1
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.
-
October 15th, 2008, 08:01 AM
#2
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};
-
October 15th, 2008, 08:32 AM
#3
Re: LINQ question (JOINs related)
 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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|