Linq错误-"NotSupportedException:用于查询运算符'Select'的不支持的重载" [英] Linq error - "NotSupportedException: Unsupported overload used for query operator 'Select'"

查看:53
本文介绍了Linq错误-"NotSupportedException:用于查询运算符'Select'的不支持的重载"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下Linq查询:

I have the following Linq query:

var tmp = 
    from container in Container
    join containerType in ContainerType on container.ContainerType equals containerType
    where containerType.ContainerTypeID == 2
    select new { ContainerID = container.ContainerID, TypeID = container.ContainerTypeID};

var results = tmp.Select((row, index) => new { row.ContainerID, row.TypeID, ContainerIndex = index })

按原样,这可以正常工作.如果添加以下内容,以便可以在LinqPad中查看结果,则会收到此消息标题中描述的错误:

As is, this works fine. If I add the following, so I can see the results in LinqPad, I get the error described in the title of this message:

results.Dump();

此错误不是LinqPad错误,它来自Linq,我不明白这是什么意思.

This error is not a LinqPad error, it's coming from Linq, and I don't understand what it means.

谢谢.

推荐答案

好吧,我还没有意识到Container是从LINQ to SQL数据源开始的.基本上,它无法将第二个投影转换为SQL.

Okay, I hadn't realised Container was a LINQ to SQL data source to start with. Basically it's failing to convert the second projection to SQL.

因此,您只想在.NET中执行该操作-您可以强制将其与AsEnumerable一起使用Enumerable.Select:

So, you want to do just that bit in .NET instead - you can force it to use Enumerable.Select with AsEnumerable:

var results = tmp.AsEnumerable()
                 .Select((row, index) => new { row.ContainerID, row.TypeID,
                                               ContainerIndex = index });

这篇关于Linq错误-"NotSupportedException:用于查询运算符'Select'的不支持的重载"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆