-
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
SQLite Query: Cast from decimal to double not translated #10642
Comments
Duplicate of #10265 You can mitigate it by casting to a .Where(x => (double)x.Price > -1) |
See the discussion in #10249 for more context. |
@bricelam casting to double doesn't seem to work. In fact, it makes it worse. I get all 5 items returned instead of the expected 3 items (or the unexpected 4 items when I don't cast as double). |
You're right. 🙁 The cast is getting lost. (Same for SELECT "x"."Name"
FROM "Items" AS "x"
WHERE "x"."Price" > -1 |
Workaroudcontext.Items.FromSql("SELECT * FROM Items WHERE CAST(Price AS REAL) > -1").Select(x => x.Name); |
Notes from triage: this is a case where the convert should not be removed since it contains semantic information needed for an appropriate translation. This is a specific case of the more general issue described in #10265 where, depending on how a type/value is mapped to the store, the translation may need to be changed or client eval may need to be triggered. |
#8861 added ability to introduce casting for projection but not for other places. |
I discussed this issue with @smitpatel. It seems we have only thought about fixing for 3.0 by preserving the convert node if you have an explicit cast to double in @smitpatel tells me that if there is no explicit cast, to avoid returning incorrect results (we can client-eval, throw or add the cast to REAL automatically), we would need additional information from the type mapping to know that decimal properties cannot be correctly compared on the server on SQLite, which is covered by #10249. I have removed #10249 from the backlog to discuss it. |
I think I already updated this to client-eval in 2.2 when there’s no cast. |
Generated SQL in new pipeline SELECT "p"."ProductID", "p"."Discontinued", "p"."ProductName", "p"."SupplierID", "p"."UnitPrice", "p"."UnitsInStock"
FROM "Products" AS "p"
WHERE CAST("p"."UnitPrice" AS REAL) > -1.0 |
My hero! lol, I'm so happy with all the improvements around types in 3.0 |
When using Sqlite as a database for EFCore, the following expression doesn't work:
This expression will return items where Price is -5. One workaround is to use Decimal.Negate and reverse the expression, but that shouldn't be needed. Both methods work fine with using SQL as the database.
Steps to reproduce
Given Db Model Item:
and db context
and the following repo:
The result of query2 produces Item 1, 2, 3 and 5, where only Item 1, 2, 3 are expected.
Further technical details
EF Core version: 2.0.01
Database Provider: Microsoft.EntityFrameworkCore.Sqlite 2.0.1)
Operating system: Windows 10
IDE: Visual Studio 2017 15.5.2
The text was updated successfully, but these errors were encountered: