Dapper
Dapper copied to clipboard
Querying with a nullable struct param always returns null
When querying for a nullable struct type, it's always returning null, even if the query returns results.
In the below example, they have the identical query - the first one is populated correctly, and the second one is null. This holds true for the other Query methods like Query, QueryFirst, etc.
There was a similar issue for tuples: #1399 - but that was resolved in 2020 so I'm guessing this is something different.
Foo f1 = conn.QueryFirstOrDefault<Foo>("SELECT 1 AS [ID], 'Something' AS [Name];");
Console.WriteLine(JsonSerializer.Serialize(f1));
Foo? f2 = conn.QueryFirstOrDefault<Foo?>("SELECT 1 AS [ID], 'Something' AS [Name];");
Console.WriteLine(JsonSerializer.Serialize(f2));
public struct Foo
{
public int ID { get; set; }
public string Name { get; set; }
}
Same issue
Same issue