Dapper icon indicating copy to clipboard operation
Dapper copied to clipboard

Querying with a nullable struct param always returns null

Open jtenos opened this issue 1 year ago • 2 comments

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; }
}

jtenos avatar May 05 '23 00:05 jtenos

Same issue

mmasdivins avatar Dec 20 '23 11:12 mmasdivins

Same issue

Wang-Ji20 avatar Jun 08 '24 07:06 Wang-Ji20