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,但我只希望匿名类型的一个属性是字典!
关于如何做到这一点有什么想法吗?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看一下 AsEnumerable 的使用。这是为了避开特定平台不支持的运营商。这意味着数据将在代码所在的位置而不是数据所在的位置进行处理。
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.
很旧了,但就这样吧。
解决了我的问题。
我用ie 直接将数据表设置为 Enumerable
Quite old, but here goes.
I solved my problem with
i.e. directly making the datatable as Enumerable.