Linq-to-SQL ToDictionary

发布于 2024-12-08 13:47:31 字数 685 浏览 2 评论 0原文

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

关于如何做到这一点有什么想法吗?

I have the following LINQ query:

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

But when I try to execute this, the ToDictionary call fails as it's not a supported LINQ-to-SQL operator. The only way around this I have seen is to call ToDictionary at the end of the query, but I only want one property of my anonymous type to be a dictionary!

Any ideas on how to go about doing this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

川水往事 2024-12-15 13:47:31

看一下 AsEnumerable 的使用。这是为了避开特定平台不支持的运营商。这意味着数据将在代码所在的位置而不是数据所在的位置进行处理。

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

Have a look at using AsEnumerable. This is designed to get round operators that are not supported by a specific platform. It means that the data will be processed where the code is rather than where the data is though.

Invoices = tag.AsEnumerable().ToDictionary(a => new AllocationDictionaryKey() { ID = a.ID, InvoiceReference = a.InvoiceReference }, a => a.Amount)
染年凉城似染瑾 2024-12-15 13:47:31

很旧了,但就这样吧。
解决了我的问题。

 from ta in dc.TransactionAllocations.AsEnumerable()

我用ie 直接将数据表设置为 Enumerable

Quite old, but here goes.
I solved my problem with

 from ta in dc.TransactionAllocations.AsEnumerable()

i.e. directly making the datatable as Enumerable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文