c# – 具有多个OR条件的Linq to Entity Join表
发布时间:2020-12-15 06:26:14 所属栏目:百科 来源:网络整理
导读:我需要编写一个可以获得以下SQL查询的 Linq-Entity状态 SELECT RR.OrderIdFROM dbo.TableOne RR JOIN dbo.TableTwo M ON RR.OrderedProductId = M.ProductID OR RR.SoldProductId= M.ProductIDWHERE RR.StatusID IN ( 1,4,5,6,7 ) 我被卡住了下面的语法 int[
我需要编写一个可以获得以下SQL查询的
Linq-Entity状态
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,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连接子句中的一个表达式的类型不正确.调用“Join”时类型推断失败. 如何为表执行多条件连接. 解决方法
您不必使用连接语法.在where子句中添加谓词具有相同的效果,您可以添加更多条件:
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(); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |