Home > Mobile >  LINQ Join with "IN" Condition in "On" Clause
LINQ Join with "IN" Condition in "On" Clause

Time:03-23

Related to this answer. And also I found something here

I have this scenario:

My SQL query looks like this:

SELECT *
FROM [tbl1] t1
LEFT JOIN [tbl2] t2 ON t1.IdX = t2.IdX AND t2.IdY IN (1,4)

I tried to translate into this LINQ:

var query = from t1 in tbl1
        join t2 in tbl2 on new{ idx = t1.IdX, idy = new byte[] { 1, 4 } } equals new{ idx = t2.IdX, idy = adresa.Idy } into tbl3
        from t3 in tbl3.DefaultIfEmpty()
    

But the problem is here new byte[] { 1, 4 }.

Is any solution to this scenario?

Thanks

CodePudding user response:

Join also can be performed by SelectMany operator. Check documentation for that Complex Query Operators

var query = 
    from t1 in tbl1
    from t2 in tbl2
        .Where(t2 => t1.Idx == t2.Idx && new byte[] { 1, 4 }.Contains(t2.Idy))
        .DefaultIfEmpty()
    select new { t1, t2 };
  • Related