Closed rhuijben closed 1 month ago
The 'System.DateTime ToDateTime(System.Object)' (Parameter 'arg0')'
looks strange as the conversion should use DateTime DateOnly.ToDateTime(DateOnly value)
here.
The query that fails is just a simple
string query = @$"
SELECT *
FROM Person
WHERE DateOfBirth = @DateOfBirth";
return await sql.ExecuteQueryAsync<Person>(query, new
{
DateOfBirth = (DateOnly?)new DateOnly(2024,1,1)
}, cancellationToken: cancellationToken);
Bug Description
For some time we used DateOnly without any issue after we installed a conversion mapper
We use DateOnly and DateOnly nullable columns.
Now I enabled
ConversionType.Automatic
to allow using enum values that aren't mapped and suddenly quering nullable enum fields broke down hard.I found that this flag enabled the builtin support for DateOnly, and was quite surprised that this breaks so hard
Exception Message:
Schema and Model:
Nothing special. Just a table with a nullable dateofbirth
CREATE TABLE Person( [ID] [int] IDENTITY(1,1) NOT NULL, [CreatedOn] datetimeoffset NOT NULL, [DateOfBirth] [date] NULL, PRIMARY KEY CLUSTERED ( [ID] ASC )
And also the model that corresponds the schema.
The original PropertyHandlerMapper mapping at the start doesn't affect any of this anymore. The cleanest fix would be that RepoDB would just support DateOnly directly without work on our side with enum conversions enabled. But going back to a working PropertyHandlerMapper would work as well. But not being able to use undefined enum values xor not using DateOnly is really a problem.
Library Version:
Example: RepoDb v1.13.1 and RepoDb.SqlServer v1.13.1