Linq to Entity Join table with multiple OR conditions

后端 未结 3 1181
死守一世寂寞
死守一世寂寞 2020-12-03 17:49

I need to write a Linq-Entity state that can get the below SQL query

SELECT  RR.OrderId
FROM    dbo.TableOne RR
        JOIN dbo.TableTwo  M ON RR.OrderedPro         


        
3条回答
  •  失恋的感觉
    2020-12-03 18:28

    You don't have to use the join syntax. Adding the predicates in a where clause has the same effect and you can add more conditions:

    var query = (from RR in context.TableOne
                 from M in context.TableTwo 
                 where RR.OrderedProductId == M.ProductID
                       || RR.SoldProductId == M.ProductID // Your join
                 where RR.CustomerID == CustomerID 
                       && statusIds.Any(x => x.Equals(RR.StatusID.Value))
                 select RR.OrderId).ToArray();
    

提交回复
热议问题