我有以下LINQ查詢:LINQ到SQL ToDictionary
var allocations =
from ta in dc.TransactionAllocations
where ta.Allocated == false
group ta by new { ta.ReceiptReference, ta.Customer } into tag
select new
{
Customer = tag.Key.Customer,
ReceiptReference = tag.Key.ReceiptReference,
Invoices = tag.ToDictionary(a => new AllocationDictionaryKey()
{
ID = a.ID,
InvoiceReference = a.InvoiceReference
},
a => a.Amount)
}
但是,當我嘗試執行這一點,ToDictionary調用,因爲它不是一個支持LINQ到SQL操作失敗。解決這個問題的唯一方法是在查詢結束時調用ToDictionary,但我只希望匿名類型的一個屬性成爲字典!
關於如何去做這件事的任何想法?
謝謝 - 我仍然得到相同的錯誤,雖然 – Chris
嘗試'tag.ToArray()。ToDictionary' – Steven
如果@史蒂文的建議不起作用,那麼它可能是最初的'集團由',翻譯不好在這種情況下,您必須首先將所有數據加載到內存中 –