簡體   English   中英

Linq-to-SQL詞典

[英]Linq-to-SQL ToDictionary

我有以下LINQ查詢:

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-to-SQL運算符。 我所看到的解決此問題的唯一方法是在查詢結束時調用ToDictionary,但是我只希望我匿名類型的一個屬性成為字典!

關於如何執行此操作的任何想法?

看看使用AsEnumerable。 這樣做是為了獲得特定平台不支持的舍入運算符。 這意味着將在代碼所在的位置而不是數據所在的位置處理數據。

Invoices = tag.AsEnumerable().ToDictionary(a => new AllocationDictionaryKey() { ID = a.ID, InvoiceReference = a.InvoiceReference }, a => a.Amount)

很老了,但是這里。 我解決了我的問題

 from ta in dc.TransactionAllocations.AsEnumerable()

即直接使數據表為可枚舉。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM