LINQ Join with "IN" Condition in "On" Clause
Asked Answered
A

1

1

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

Anticoagulant answered 16/3, 2022 at 10:28 Comment(1)
Try : join t2 in tbl2.Where(x => (x.Udy == 1 ) || (x.Udy == 4 ))Peden
F
2

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 };
Fouquiertinville answered 16/3, 2022 at 10:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.