【发布时间】:2011-10-05 03:21:37
【问题描述】:
我正在尝试将“SQL Outer Apply”转换为 Linq。 SQL 是:
select Currencies.Name, Currencies.Sign ,a.ActualPrice
from Currencies
outer apply (select CurrencyID,ActualPrice from Prices
where ProductID=5 and Currencies.ID=Prices.CurrencyID)a
我尝试了以下 Linq,但得到了一行,而不是 SQL 语句给我的每种货币的一行。
from c in Currencies
from p in Prices.DefaultIfEmpty()
where p.ProductID.Equals(5) && c.ID==p.CurrencyID
select new {c.Name, p.ActualPrice}
有什么解决办法吗?
【问题讨论】:
-
您的原始查询很容易被重新定义为左外连接,以下问题至少涵盖了一个 linq 等效项:stackoverflow.com/questions/2742814/left-outer-join-problem
标签: sql linq apply outer-join