NET Core 3.1 Required String Properties - SqlException: An expression of non-boolean type specified in a context where a condition is expected, near 'THEN'. #19444
Labels
area-query
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
type-bug
Milestone
Moved from dotnet/core#4063 filed by @robinwilson16
Upgrading projects from .NET Core 3.0 to 3.1 generates invalid SQL in some situations and I have tracked the issue down to being the case that .NET Core 3.1 generates an invalid SQL case statement for a required attribute of a data model which generates correctly on .NET Core 3.0.
Here is an example of some C# code where the code for the
BodyTypes
entity is ok after upgrade as does not have the required attribute but the code for theMakes
entity generates invalid an invalid case statement.Properties from the object model:
C# Code in code behind:
Using SQL Profiler, before this code generated the following:
BodyTypes:
Makes:
After migration to NET Core 3.1 sp_executesql is no longer used for either but now the SQL generated for
Makes
is invalid:BodyTypes (is still valid):
Makes:
If I switch the project back to 3.0 then it is fine again but as soon as I change it to 3.1 it stops working correctly as the SQL being generated is invalid.
The exception generated is:
This is the same error you get if you run the SQL in SSMS.
Workarounds are either to:
The text was updated successfully, but these errors were encountered: