Generated EF Core connection assumes datetime2
Because of the way EF Core (incorrectly IMNSHO) works, datetime2 is assumed for SQL Server columns mapped to C# DateTime.
Is there a way to have the schema generated correctly to map to SQL Server datetime when the column actually contains datetime, or to access HaveColumnType to override the mapping for incorrect columns.
Comments
I'm not sure what you're asking - LINQPad doesn't generate schema, it does the reverse (i.e., scaffolds). When it does so, both datetime and datetime2 end up as System.DateTime.
The issue occurs with the generaeted scaffolding for legacy SQL datatime columns - EF Core assumes the System.DateTime type should map to datetime2, generates a datetime2 acceptable string for constant expressions in queries, which then fails to convert to datetime on the SQL Server side. The scaffold should generate
HaveColumnType("datetime")
when scaffolding for a SQL Server datetime column.See https://github.com/dotnet/efcore/issues/27464#issuecomment-1042877546