我一直试图用SQLProvider复制它:
SELECT c.ticker, hc.ticker
FROM currencies c
LEFT JOIN currencies hc on hc.id = (CASE WHEN c.offshore_hedging_currency_id IS NULL THEN c.id ELSE c.offshore_hedging_currency_id END)
我尝试了以下和变体,但我似乎无法获得结果。
let q =
query {
for c in db.Main.Currencies do
let tmp = if c.OffshoreHedgingCurrencyId.IsSome then c.OffshoreHedgingCurrencyId.Value else c.Id
join hc in db.Main.Currencies on (tmp = hc.Id)
select (c.Ticker, hc.Ticker)
}
offshore_hedging_currency_id可以为空。
我还尝试了一个更简单的方法:
SELECT c.ticker, hc.ticker
FROM currencies c
LEFT JOIN currencies hc on hc.id = c.offshore_hedging_currency_id
但是由于nullables被转换为选项(因此编译器抱怨)
,以下内容将无效let q =
query {
for ccy in db.Main.Currencies do
leftOuterJoin ohc in db.Main.Currencies on (ccy.OffshoreHedgingCurrencyId = ohc.Id) into result
for ohc in result do
select (ccy.Ticker, ohc.Ticker)
}
非常感谢