Querying with a nullable struct param always returns null
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 18.4k
- Forks
- 3.7k
- Avg merge
- 5h 8m
- Merged PRs (30d)
- 1
Description
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; }
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the provided C# Foo struct and SELECT query, then trace the QueryFirstOrDefault path used for nullable structs and compare it with the non-nullable case. Done means Foo? is populated from the returned row for QueryFirstOrDefault and related Query methods, with a regression test covering the behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, sql
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100