Wednesday, 15 September 2010

c# - How to do linq joins with multiple conditions + ORs -



c# - How to do linq joins with multiple conditions + ORs -

i know how linq bring together multiple conditions , ors.

example:

var = (from d in context.table1 bring together b in context.table2 on new {r1 = d.col1, r2 = d.col2} equals new {r1 = b.col1, r2 = b.col2} || b.col3.tolower() equals "xyz" bd k in bd.defaultifempty()

the ors part blowing up.

sql example:

select * table1 t1 left bring together table2 t2 on (t1.col1 = t2.col1 , t1.col2 =t2.col2) or (t1.col1 = t2.col1 , t2.col2 = 'xyz')

explanation:

t1.col1 must match t2.col1 - required join

then

t1.col2 has match t2.col2 unless t2.col2 = "xyz" bring together on col1

try moving "join" "where" clause ala ansi 82:

var = (from d in context.table1 b in context.table2 (b == null) || (d.col1 = b.col1 && d.col2 == b.col2 ) || (b.col3.tolower() == "xyz")

c# linq

No comments:

Post a Comment