在 C# EF 中,Where(o=>o.Equals(x)) 是否被视为客户端函数?

In C# EF, does Where(o=>o.Equals(x)) get treated as a client-side func?

遇到 .Where(o => o.x == y) 更改为 .Where(o => o.x.Equals(y)) 的代码。我知道 == 是由 EF 的 SQL 生成器解析出来在服务器上执行的,但不确定 .Equals()。很明显,这种改变是出于习惯,也许有人有 C++ 背景,没有考虑 == 会被解析为表达式,而不是作为函数执行,并且会被转换为SQL。此更改编译并运行,但我想知道是否是因为 EF 将其视为 Func 而不是表达式,因此可能执行通用查询并将过滤器移动到客户端,或类似的荒谬。

从 EF 版本 6 开始,Linq-To-Entities 不在客户端中执行任何类型的过滤。如果您尝试在 EF IQueryable 上执行任何类型的不受支持的函数(意味着它无法转换为数据库提供程序),它会抛出异常。

所以答案是:不,它不是在本地执行。

PS: 我在某处读到此功能是计划添加到 EF7 中的,但这未经证实,只是猜测

更新:link 来源:http://blogs.msdn.com/b/adonet/archive/2014/10/27/ef7-v1-or-v7.aspx

引用相关部分以防 link 死机:

An example of this is how queries are processed. In EF6.x the entire LINQ query was translated into a single SQL query that was executed in the database. This meant your query could only contain things that EF knew how to translate to SQL and you would often get complex SQL that did not perform well.

In EF7 we are adopting a model where the provider gets to select which bits of the query to execute in the database, and how they are executed. This means that query now supports evaluating parts of the query on the client rather than database. It also means the providers can make use of queries with multiple results sets etc., rather than creating one single SELECT with everything in it.

我 运行 SQL 探查器。它生成了“[table].[x] = 'y'”,正如最初打算使用“==”。