Skip to content

CommandUtils.As: accept a DateOnly source (Npgsql 10 'date' columns) - #203

Merged
mgravell merged 1 commit into
mainfrom
dateonly-source-coercion
Aug 20, 2026
Merged

CommandUtils.As: accept a DateOnly source (Npgsql 10 'date' columns)#203
mgravell merged 1 commit into
mainfrom
dateonly-source-coercion

Conversation

@mgravell

Copy link
Copy Markdown
Member

Fixes#202.

Npgsql 10 changed reader.GetValue() for a date column to return DateOnly rather than DateTime; DateOnly doesn't implement IConvertible, so As<DateTime[?]>'s fallback through Convert.ToDateTime threw InvalidCastException. Bisected empirically: the DateOnlyTimeOnly Postgres tests pass on Npgsql 9.0.2 and fail on 10.0.2 (which arrived with #174) — unseen until now because the Postgres integration tests need local Docker.

  • As<DateTime[?]> from a DateOnly converts via ToDateTime(TimeOnly.MinValue)
  • As<TimeOnly[?]> from a DateOnly answers default — the same answer a zero-time DateTime gives, which is the contract the integration test already documents
  • new docker-free unit tests cover the matrix directly, so the coverage no longer depends on a live container

With this, the full unit suite is green on all three TFMs locally (Docker up): 466/466 net10, 466/466 net8, 458/458 net48.

Npgsql 10 changed reader.GetValue() for a 'date' column to return DateOnly
rather than DateTime; DateOnly does not implement IConvertible, so the
As<DateTime[?]> fallback through Convert.ToDateTime threw InvalidCastException.
Bisected empirically: the DateOnlyTimeOnly Postgres tests pass on Npgsql 9.0.2
and fail on 10.0.2, which arrived with #174 - unseen because the Postgres
integration tests need local Docker.
As<DateTime[?]> now converts via ToDateTime(TimeOnly.MinValue), and
As<TimeOnly[?]> answers default for a date - the same answer a zero-time
DateTime gives, which is the contract the integration test documents. New
docker-free unit tests cover the matrix directly, so this coverage no longer
depends on a live container.
Fixes#202
@mgravell
mgravell merged commit dcfbe2e into mainAug 20, 2026
2 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CommandUtils.As<DateTime> throws on a DateOnly source (Npgsql 10 'date' columns)

1 participant

@mgravell