[英]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.