Open davidrot opened 9 months ago
Today I found a possible solution, then I guess it is not a bug.
public class StringToDateTimePropertyHandler : IPropertyHandler<string, DateTime>
{
public DateTime Get(string input, PropertyHandlerGetOptions property)
{
var output = DateTime.Parse(input, null, DateTimeStyles.RoundtripKind);
return output;
}
public string Set(DateTime input, PropertyHandlerSetOptions property)
{
property.DbParameter.DbType = DbType.String;
return input.ToUniversalTime().ToString("o");
}
}
Please leave this one open as we will look on how to fix this one without having to create the Property Handler.
Bug Description
I have found a bug related to the where condition, what is not matching due to wrong DbType of the DbParameter. Luckily, I am able to reproduce it in a kind of unit test using sqlite.
In this example, count (other methods could be affected as well) is not returning the right value. The condition is simple, but the types are a bit different. Database is using string/text, C# is using DateTime. Therefore, I use a PropertyHandlerMapper.
I debugged down the whole path and found that on DbCommandExtensions.cs:63 the DbType of the DbParameter changed to DateTime. I would assume this is wrong due to the PropertyHandlerMapper. The PropertyHandler is called a view lines later (DbCommandExtensions.cs:312-315) the dbtype is not set.
DbCommandExtensions.cs:63
Example: