本文介绍了LINQ到实体加入表与多个OR条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要写一个LINQ实体的状态,可以得到下面的SQL查询
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.OrderedProductId = M.ProductID OR RR.SoldProductId= M.ProductID WHERE RR.StatusID IN ( 1, 4, 5, 6, 7 )我坚持以下语法
int[] statusIds = new int[] { 1, 4, 5, 6, 7 }; using (Entities context = new Entities()) { var query = (from RR in context.TableOne join M in context.TableTwo on new { RR.OrderedProductId, RR.SoldProductId} equals new { M.ProductID } where RR.CustomerID == CustomerID && statusIds.Any(x => x.Equals(RR.StatusID.Value)) select RR.OrderId).ToArray(); }这给了我下面的错误
错误50联接子句中的类型表现之一是不正确。类型推断在调用加入失败。
我怎样才能做一个多重条件加盟的表。
How can I do a Multiple condition join for a table.
推荐答案您不必使用join语法。在其中,子句添加谓词具有相同的效果,你可以添加更多的条件:
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();更多推荐
LINQ到实体加入表与多个OR条件
发布评论