3

我试图模仿:

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

我已经阅读了有关创建匿名类型并将它们设置为彼此相等的信息,但是当使用小于和大于比较日期时,这不起作用。

4

1 回答 1

5

看来这个答案就是我想要的。

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()

结合这个答案,我能够简化为:

from ledgers in ledgerEntries
from currencies in currencyExchange.Where(
    currency => currency.CurrencyCode == ledgers.CurrencyCode
    && currency.StartingDate <= ledgers.DocumentDate 
    && currency.EndingDate <= ledgers.DocumentDate).DefaultIfEmpty()
于 2013-04-25T15:37:32.350 回答