DateOnly/DateTime coercion gaps on 'date' columns (breaks with Npgsql 10, and SqlClient the other way)
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 18.4k
- Forks
- 3.7k
- Avg merge
- 5h 8m
- Merged PRs (30d)
- 1
Description
Sibling of DapperLib/DapperAOT#202 (fixed on the AOT side in DapperLib/DapperAOT#203); vanilla has the same gap, in both directions. Adjacent to but distinct from #2072.
Npgsql 10 changed reader.GetValue() for a date column to return DateOnly rather than DateTime. Probed against Dapper 2.1.72 with a date column holding 2021-01-01:
| probe | Npgsql 9.0.2 (DateTime box) |
Npgsql 10.0.2 (DateOnly box) |
SqlClient (DateTime box) |
|---|---|---|---|
Query<DateTime> |
✅ | ❌ DataException (inner: DateOnly is not IConvertible) |
✅ |
Query<DateTime?> |
✅ | ❌ same | ✅ |
POCO DateTime member |
✅ | ❌ same | ✅ |
POCO DateOnly member |
❌ DataException (DateTime box) |
✅ | ❌ same as Npgsql 9 |
So there is no DateOnly↔DateTime coercion in either direction on the read path: providers that box DateTime break DateOnly members, and Npgsql 10 (boxing DateOnly) breaks DateTime members and typed scalars. Each provider/version combination has a working direction and a broken one, which makes upgrading Npgsql a breaking change for any model that reads dates as DateTime.
The AOT-side fix was simply to accept either box shape in the conversion helper, keyed on the runtime value — DateOnly → ToDateTime(TimeOnly.MinValue) for a DateTime target, and the equivalent in reverse; the same treatment fits FlexibleConvert/the parse paths here.
Repro is a 30-line console app (fresh postgres:16 container + select '2021-01-01'::date); happy to PR the fix.
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 at FlexibleConvert and the parse paths mentioned in the issue, then reproduce the behavior with the described 30-line console app using a date column. Trace conversions for both DateOnly and DateTime runtime values. Done means reads work in both directions for typed scalars and POCO members across the provider boxing shapes described.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, postgresql, sql
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 67/100