C# Linq到SQL ToDictionary

C# Linq到SQL ToDictionary,c#,linq,linq-to-sql,todictionary,C#,Linq,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, ReceiptReferen

我有以下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,但我只希望匿名类型的一个属性是dictionary


关于如何着手做这件事有什么想法吗

看看如何使用AsEnumerable。这是为了让不受特定平台支持的运营商参与进来。这意味着数据将在代码所在的位置进行处理,而不是在数据所在的位置进行处理

Invoices = tag.AsEnumerable().ToDictionary(a => new AllocationDictionaryKey() { ID = a.ID, InvoiceReference = a.InvoiceReference }, a => a.Amount)
很老了,但现在开始了。 我用电脑解决了我的问题

 from ta in dc.TransactionAllocations.AsEnumerable()

i、 e.直接将数据表设置为可枚举。

尝试
标记.ToArray().ToDictionary
如果@Steven的建议不起作用,那么可能是初始的
分组方式转换不好,在这种情况下,您必须先将所有数据加载到内存中