Closed Shiko1st closed 1 year ago
We need a stand-alone repro here. There are too many errors in the snippets above to effectively reproduce the error. The root cause of error is when trying to convert a character string to one of the datetime related types in SQL when the format of the string does not identify the requested type correctly. That means it is data dependent error.
Further, in the snippets above
DAILY_RESULTS
table* no info about `DAILY_RESULTS` table
Appended to description as §2.2
* What exactly is the computed column SQL setting
Was described initially, now §2.3
* What is queryString in the LINQ query?
Query described at the beginning of the "Custom query" section, now §2.1
* In the generated SQL the user provided SQL contains cast to datetimeoffset which can be one of the error point.
This is a custom query I'm talking about. Initially there were no cast (see §2.1). When this error happend I tried to play with various output date types in custom query and DailyResultInfo class.
* zzz.GetDays is passing parameter value of first parameter in quotes. For constant quotes would be needed but not when passing value as parameter.
It seems this is the problem. I've got the same error playing with parameters in query editor. But this call was not changed and worked in EF Core 3.1 welll... Is it possible EF Core 5 formats final query in different way?
Is it possible EF Core 5 formats final query in different way?
We haven't changed anything in this area. You should be able to compare the SQL generated in 3.1/5.0 easily.
EF Team Triage: Closing this issue as the requested additional details have not been provided and we have been unable to reproduce it.
BTW this is a canned response and may have info or details that do not directly apply to this particular issue. While we'd like to spend the time to uniquely address every incoming issue, we get a lot traffic on the EF projects and that is not practical. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we use canned responses for common triage decisions.
It seems a breaking change from EF Core 3.1 to EF Core 5. I having this error while execution of custom query that worked well in EF Core 3.1:
This error occured both on Azure SQL Server and MsSqlLocalDb on my local machine.
What do we have
1. No-key entity
2. Custom query
2.1. Query itself
2.2. DAILY_RESULTS table
Is described by this class:
2.3. DAILY_RESULTS.Day field is defined as date by conversion from other field:
2.4. GetDays is a function that generates a list of dates
It returns a list of dates starting from a specified date. It allows us to have a record in result set even if there were no record in DAILY_RESULTS table for some day and specified user.
2.5. Query execution
Query is executed like this:
Where
queryString
is a custom query described in (1). EF Core 5 translates this into something like this:The problem
Everything was OK on EF Core 3.1.
But after migration to EF Core 5, this query leads to this exception:
I've found #14095 where people mentioned that there were a problem with conversion to DateTime in certain conditions. I tried to play with types and type conversion in various combinations:
DailyResultInfo.Day
was changed toDateTimeOffset
CAST(days.Day as datetimeoffset) as Day
...but nothing helps.
Attempt to specify sql type directly in model builder like this
eb.Property(e => e.Day).HasColumnType("date");
also doesn't help.Remove sorting doesn't help.
I tried to trace this in debugger and on the first look it shows me that TdsParser even don't enter actual data parsing.
The same query being executed using Dapper over the same DbConnection and being executed using external tool like DataGrip parsed well and returns data as expected.
Environment
.NET Core 5 ASP.NET Core 5 Microsoft.EntityFrameworkCore.SqlServer 5.0.0 Microsoft.Data.SqlClient 2.1.0 Azure SQL Server MsSqlLocalDb OS: Win7 IDE: Rider 2020.2.4