我有一个存储过程的片段:



...
SELECT B.BinID, AverageCost, SUM(Qty) AS Qty
FROM #CurrentReturn R INNER JOIN Bins B ON R.BinCode = B.BinCode AND B.StoreroomID = @StoreroomID
...





@StorerroomID是SP参数之一。

现在,我正在尝试将其转换为LINQ to Entities,



var AverageCostList = from r in CurrentReturn
                      join b in BinQuery on new {r.BinCode, b.StoreroomID} equals new {b.BinCode, storeroomID}





由于L.H.S.上的类型不起作用的equals不能包含b中的字段。

那么,有什么方法可以将这种内部联接SQL转换为LINQ?

最佳答案

我会把B.StoreroomID = @StoreroomID比较放到where子句中

from r in CurrentReturn
join b in BinQuery
on r.BinCode equals b.BinCode
where b.StoreroomID == storeroomID

关于c# - 如何将此内部联接T-SQL转换为LINQ-to-Entities?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35332438/

10-08 22:23