-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Description
Hi,
Using Microsoft.Data.SqlClient 5.2.0 and Dapper 2.1.44, we've noticed an issue with the new DateOnly type support from #2051.
Using a simple class such as
public class PersonTest
{
public string FirstName { get; set; }
public DateOnly FromDate { get; set; }
}
and a QueryAsync with
public async Task<PersonTest> GetPerson(string Username)
=> (await QueryAsync<PersonTest>(AdminProcs.GetPerson, new { Username })).FirstOrDefault();
we get an error response of
{
"type": "System.Data.DataException",
"title": "Dapper",
"status": 500,
"detail": "Error parsing column 1 (FromDate=Ed - String)",
"traceId": "00-ae3a4c30e843c63d927302fde275a754-ca340c148ee9f15f-00"
}
The data, returned by MS SQL Server, as a varchar and DateTime type, are as follows:
FirstName FromDate
-------------------------------------------------- -----------------------
Ed 2019-10-01 00:00:00.000
The issue seems to be that it is trying to parse column 1 as the FromDate with the value of Ed, which is in column 0. Hence the "off by one" error.
Running this with Dapper 2.1.35, using the the previous custom solution from #1715, does not have this error.
Staying on 2.1.44, if we remove FromDate
from PersonTest
, it works fine with just the FirstName.
Changing FromDate in PersonText to a more open type, such as string, also works fine.
Changing the SQL type, as e.g., as MS SQL Date, or an int or varchar in ISO8601 format, doesn't have any effect.