LINQ 在 "On" 子句中加入 "IN" 条件

LINQ Join with "IN" Condition in "On" Clause

与此相关answer. And also I found something here

我有这个场景:

我的 SQL 查询如下所示:

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

我试着翻译成这个 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()
    

但是问题就在这里new byte[] { 1, 4 }

这种情况有什么解决办法吗?

谢谢

Join 也可以由 SelectMany 运算符执行。检查文档 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 };