我想模仿:
DB1 AS A LEFT OUTER JOIN
DB2 AS B
ON A.[Currency Code] = B.[Currency Code]
AND A.[Document Date] >= B.[Starting Date]
AND A.[Document Date] <= B.[Ending Date]
这就是我现在所拥有的:
from ledgers in ledgerEntries
join currency in currencyExchange
on ledgers.CurrencyCode equals currency.CurrencyCode
into c
from currencies in c.DefaultIfEmpty()
where
ledgers.DocumentDate >= currencies.StartingDate
&& ledgers.DocumentDate <= currencies.EndingDate
我已经阅读过关于创建匿名类型并将它们设置为彼此相等的内容,但是当使用小于和大于比较日期时,这不起作用。
答案 0 :(得分:5)
似乎this回答是我正在寻找的。 p>
from ledgers in ledgerEntries
join currency in currencyExchange
on ledgers.CurrencyCode equals currency.CurrencyCode
into c
from currencies in c.Where(currency => currency.StartingDate <= ledgers.DocumentDate
&& currency.EndingDate <= ledgers.DocumentDate).DefaultIfEmpty()
结合this回答,我能够简化为:
from ledgers in ledgerEntries
from currencies in currencyExchange.Where(
currency => currency.CurrencyCode == ledgers.CurrencyCode
&& currency.StartingDate <= ledgers.DocumentDate
&& currency.EndingDate <= ledgers.DocumentDate).DefaultIfEmpty()