dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.8k stars 3.2k forks source link

Represent query parameters with a dedicated type instead of ParameterExpression #35089

Closed roji closed 3 days ago

roji commented 1 week ago

Our funcletizer identifies captured variables in the incoming query tree (member accesses over compiler-generated closure types), and converts these to ParameterExpressions which represent external query parameters; these are later translated to e.g. SqlParameter. These ParameterExpressions have a very different meaning than the incoming compiler-generated ParameterExpression, which represent lambda parameters which never exist in the final translation of the query (they are replaced during translation with the thing they represent).

This design has the following issues:

The solution here seems quite simple: introduce a new QueryParameterExpression which is completely unrelated to ParameterExpression (extension node):

Note: this would be a breaking change to (non-relational) providers as they'd need to translate the new node to whatever their query parameter is (SqlExpression for relational).