Linq Left Outer Join
Posted
by Neil
on Stack Overflow
See other posts from Stack Overflow
or by Neil
Published on 2010-05-26T21:16:41Z
Indexed on
2010/05/26
21:21 UTC
Read the original article
Hit count: 418
LINQ
|outer-join
I am new to LINQ and am trying to convert a SQL query to LINQ:
SQL:
left outer join PRODUCT_BEST_USE pbu on pbu.PRODUCT_GUID = @uProductId and pbu.BEST_USE_GUID = bu.BEST_USE_GUID
LINQ:
from PBU in PRODUCT_BEST_USE.Where(PBU=>PBU.PRODUCT_GUID == p.PRODUCT_GUID).DefaultIfEmpty()
When I add and PBU.BEST_USE_GUID equals BU.BEST_USE_GUID, I get an error:
"A query body must end with a select clause or a group clause"
Here is the full Linq query:
from p in PRODUCT
join BU in BEST_USE on p.CATEGORY_GUID equals BU.CATEGORY_GUID
from PBU in PRODUCT_BEST_USE.Where(PBU=>PBU.PRODUCT_GUID == p.PRODUCT_GUID).DefaultIfEmpty() and PBU.BEST_USE_GUID equals BU.BEST_USE_GUID
where p.PRODUCT_GUID == new Guid("d317752b-581d-4f43-92fa-4a4af91009f5")
select new { BU.NAME, PBU.PRODUCT_BEST_USE_GUID }
© Stack Overflow or respective owner