-
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
Can't translate property AS Nullable<double> #20179
Comments
verified this fails in 3.1.2 and works on current master. We generate the following sql: SELECT (
SELECT TOP(1) CONVERT(float, [p].[Value])
FROM [Properties] AS [p]
WHERE ([p].[Identifier] = N'Price') AND ([p].[ThingId] = [t].[Guid])
ORDER BY CONVERT(float, [p].[Value]) DESC) AS [Value]
FROM [Things] AS [t]
ORDER BY (
SELECT TOP(1) CONVERT(float, [p0].[Value])
FROM [Properties] AS [p0]
WHERE ([p0].[Identifier] = N'Price') AND ([p0].[ThingId] = [t].[Guid])
ORDER BY CONVERT(float, [p0].[Value]) DESC) |
@TanielianVB as a workaround, you can use hard cast to var q = (from price in db.Properties
where price.Identifier == "Price"
orderby Convert.ToDouble(price.Value) descending
select new
{
price.ThingId,
Value = (double?)Convert.ToDouble(price.Value) //as double?
}); |
dupe of #5783 |
@TanielianVB the reason why the first query worked is that the cast was in the projection - EF allows client evaluation of projections. In the second query, you composed on top of it, and that caused an error. Any operation (where, distinct etc) would have had the same result |
Thank you! |
Hi,
When filtering or ordering a property filled from a let variable I get the "could not be translated" error.
Steps to reproduce
With the following tables:
The following sample:
I'm getting this output:
I don't understand why it is not working if the value is correctly calculated on the database side.
Further technical details
EF Core version: 3.1.2
Database provider: Microsoft.EntityFrameworkCore.SqlServer or Npgsql.EntityFrameworkCore.PostgreSQL both 3.1.2
Target framework: (e.g. .NET Framework 4.7.2
Operating system: Windows
IDE: Visual Studio 2019 16.4.5
The text was updated successfully, but these errors were encountered: