首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Linq-to-SQL ToDictionary

Linq-to-SQL ToDictionary
EN

Stack Overflow用户
提问于 2011-10-06 16:14:12
回答 2查看 1.2K关注 0票数 2

我有以下LINQ查询:

代码语言:javascript
复制
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,但我只希望匿名类型的一个属性是字典!

有没有关于如何开始这样做的想法?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-10-06 16:19:03

看看如何使用AsEnumerable。这是为了获取特定平台不支持的舍入运算符。这意味着数据将在代码所在的位置而不是数据所在的位置进行处理。

代码语言:javascript
复制
Invoices = tag.AsEnumerable().ToDictionary(a => new AllocationDictionaryKey() { ID = a.ID, InvoiceReference = a.InvoiceReference }, a => a.Amount)
票数 3
EN

Stack Overflow用户

发布于 2012-10-04 19:31:17

很老了,但现在开始了。我解决了我的问题

代码语言:javascript
复制
 from ta in dc.TransactionAllocations.AsEnumerable()

即直接使数据表成为可枚举的。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7671708

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档