0

How to convert the below SQL query into LINQ query for C#.net

Select t1.id,t2.Name
From table1 t1
INNER JOIN table t2
ON ((t1.column3 is null and t1.id = t2.id)
    OR( t.Column3 is NOT NULL and t1.column3 = t3.Column3))
Join tblXYZ  xyz on t1.column4 = xys.columnn2

I was unable to add or condition after first set up comparison in linq query, please suggest correct way to achieve this in linq.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Raj
  • 1
  • 1
    The "below SQL query" is not valid. – Ivan Stoev Oct 19 '16 at 21:07
  • 3
    Possible duplicate of [LINQ to SQL complex join with mixed conditions](http://stackoverflow.com/questions/6491661/linq-to-sql-complex-join-with-mixed-conditions) – jmoerdyk Oct 19 '16 at 21:09
  • Possible duplicate of [Linq2Sql join by multiple columns (by OR operator)?](http://stackoverflow.com/questions/40080458/linq2sql-join-by-multiple-columns-by-or-operator) – Gilad Green Oct 19 '16 at 21:29

1 Answers1

0

Making some assumptions about what you meant, I would suggest hoisting the OR to a union:

(from t1 in table1
 join t2 in table2 on t1.Column3 equals t2.Column3
 join xyz in tblXYZ on t1.Column4 equals xyz.column2
 where t1.Column3 != null).Union(
 from t1 in table1
 join t2 in table2 on t1.id == t2.id
 join xyz in tblXYZ on t1.Column4 equals xyz.column2
 where t1.Column3 == null)
NetMage
  • 26,163
  • 3
  • 34
  • 55