我试图将下面的Oracle Sql查询转换为linq,但没有取得太大的成功。我不知道如何处理AND ShipSeq = i.ShipSeq(+)
,我知道这是在Oracle中的LEFT OUTER JOIN
。我在LinqPad中测试下面的Linq查询,在那里我没有得到任何语法错误,但是它在执行查询时出错。有任何想法吗?将具有左外部联接的Oracle SQL查询转换为Linq
的Oracle SQL查询
SELECT *
FROM CustomerShip,
(SELECT DISTINCT b.ShipSeq AS shipSeq
FROM Orders a,
CustomerShip b
WHERE a.OrderId IN (SELECT OrderId
FROM Orders
WHERE CustomerId = @CustomerId
AND OrderType <> 'A')
AND b.CustomerId = @CustomerId
AND b.ShipSeq = a.CustShip
AND OrderStatus <> 'C'
GROUP BY b.ShipSeq) i
WHERE CustomerId = @CustomerId
AND (Address NOT LIKE '%RETAIL%STORE%')
AND ShipSeq = i.ShipSeq(+)
ORDER BY ShipTo DESC, OrderDate DESC;
LINQ查询
var query = from s in CustomerShip
join m in Orders on s.ShipTo equals m.ShipTo into temp
from x in temp.DefaultIfEmpty()
where (from o in Orders
from c in CustomerShip
where (from x in CustomerOrders
where x.CustomerId == customerId
&& !x.OrderType.Equals("A")
select x.OrderId).Contains(o.OrderId)
&& c.CustomerId == customerId
&& c.ShipTo == o.ShipTo
&& !o.OrderStatus.Equals("C")
select c.ShipTo).Distinct().Contains(s.ShipTo)
&& s.CustomerId == customerId
&& !s.Address.Contains("RETAIL")
&& !s.Address.Contains("STORE")
orderby s.ShipTo descending, s.OrderDate descending
select s;
这可能有助于(https://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b)有一个部分上加入 –