Mohan Kumar
Mohan Kumar

Reputation: 6056

let statement and outer join in LINQ to SQL

How to use the let statement in outer join of LINQ to SQL?

Something like below,

from a in tableA
from b in tableB.where(o =>  a.Key == o.Key).DefaultIfEmpty() //outer join
let x = b.objectBB  
where b != null && x != null && x.FilterCode == "X"

So,

  1. Does the above query is fine?
  2. Will the 'let' fail if 'b' is null ?
  3. what will happen with the where clause on 'x'? Does this filter work fine?

Any better way to achieve this also much welcome.!

Upvotes: 1

Views: 974

Answers (1)

Brett Green
Brett Green

Reputation: 3755

Seems to me that if you want both sides to be not null, don't you just want an inner join?

from a in tableA
join b in tableB on a.Key equals o.Key
where b.FilterCode == "X"

Upvotes: 1

Related Questions