-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Query: Generate parameter for member accesses on enclosing class #17172
Comments
Two remarks:
|
https://docs.microsoft.com/en-us/ef/core/modeling/relational/data-types If you have a data type in database which is different from default then you have to manually configure it to tell EF which data type to use. Once you specify correct one, query would work automatically. |
Thanks for the link. This is where I actually learned about the default "DateTime => datetime2" mapping, yet I was hoping for a more comprehensive mapping table listing all data types. Agree, with the manual mapping it works, but the generated non-parameterized query is still sub-optimal (or at least unreasonably different from 2.x). |
Can you also share generated queries and explain why it is sub-optimal? |
With manual mapping of OrderDate to 'datetime' my -- 3.0.0-preview8.19405.11
SELECT [o].[OrderID], [o].[OrderDate]
FROM [Orders] AS [o]
WHERE [o].[OrderDate] < '2019-08-15T18:26:13.227'
-- 2.2.6
SELECT [o].[OrderID], [o].[OrderDate]
FROM [Orders] AS [o]
WHERE [o].[OrderDate] < @__CurrentDate_0 I'd say I'd rather prefer the old variant according to https://www.red-gate.com/simple-talk/sql/t-sql-programming/performance-implications-of-parameterized-queries/
|
If you use local variable from closure then it would generate parameter since you can change the value of variable in local closure. When constants appear in expression (other than constant of closure), then there is no way to change value in expression tree hence we inline them. |
Yes, I also noticed that with local variables it works as before (sounds like a workaround yet quite painful considering the amount of queries to revisit). Just out of curiosity why had it been decided to translate a property expression to |
In 2.x, we used Remotion.Linq library which did some processing around it so we never get to see actual expression tree in that way. As it stands in 3.0, there is no way to identify such difference inside expression tree to generate parameter. The only thing is possible is to generate parameter for every constant we use but that may not be really useful. |
I see. In my eyes though this sudden change in behavior may have implications serious enough for being at least worth mentioning on the "breaking changes" list. Of course the impact depends on the actual code, but who knows how many programs out there are using properties in LINQ queries today? Database servers may suffer greatly if they suddenly get bombarded with zillions of SQL queries which only differ in some excessively inlined values. I'd rather say everything that isn't a hard-coded expression like |
Except for static readonly fields const fields are always inlined as constant by compiler Resolves #17172
Except for static readonly fields const fields are always inlined as constant by compiler Resolves #17172
Except for static readonly fields const fields are always inlined as constant by compiler Resolves #17172
The first method doesn't differ much from the second one, yet it passes whilst the other one fails. The error message shows no connection to the new stricter LINQ translation approach of 3.0, which is probably not the case here anyway.
Further technical details
EF Core version: 3.0.0-preview8.19405.11
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10
IDE: Visual Studio Professional 2019 16.2.2
The text was updated successfully, but these errors were encountered: