【发布时间】:2013-04-11 12:40:20
【问题描述】:
我需要写一个Linq-Entity状态,可以得到下面的SQL查询
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 连接子句中的其中一个表达式的类型不正确。调用“加入”时类型推断失败。
如何对表进行多条件联接。
【问题讨论】:
标签: c# linq entity-framework linq-to-entities