LINQ到实体加入表与多个OR条件

编程入门 行业动态 更新时间:2024-10-27 22:29:41
本文介绍了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条件

本文发布于:2023-06-03 10:01:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/473704.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   实体   条件   LINQ

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!