Skip to content

Add async members to SafeDataReader - #4976

Merged
rockfordlhotka merged 3 commits into
mainfrom
issue-4975/async-safedatareader
Oct 30, 2026
Merged

rockfordlhotka merged 3 commits into
mainfrom
issue-4975/async-safedatareader

Conversation

@rockfordlhotka

Copy link
Copy Markdown
Member

Summary

  • SafeDataReader has async members:
    • ReadAsync, NextResultAsync and CloseAsync.
    • IsDBNullAsync and GetFieldValueAsync<T>, by ordinal or by column name.
    • Async versions of the typed getters that return defaults for nulls, the same as the sync getters: GetStringAsync, GetValueAsync, GetInt16/32/64Async, GetDoubleAsync, GetFloatAsync, GetDecimalAsync, GetBooleanAsync, GetByteAsync, GetGuidAsync, GetDateTimeAsync, GetDateTimeOffsetAsync and GetSmartDateAsync.
    • IAsyncDisposable (DisposeAsync).
  • The new members use the underlying DbDataReader, which every ADO.NET provider returns. If the wrapped reader isn't a DbDataReader, they run synchronously.
  • The typed getters check for null asynchronously and then call the provider's typed getter. A plain (T) cast would fail where a provider returns a different type: SQLite returns long for INTEGER columns.
  • SafeSqlDataReader now inherits ReadAsync, NextResultAsync and GetFieldValueAsync<T> instead of declaring SqlClient-only versions. It keeps IsDbNullAsync, marked [Obsolete], which forwards to IsDBNullAsync.
    • Breaking change: code compiled against the old SafeSqlDataReader async methods must be recompiled. Source code is unchanged.
  • Release notes and Upgrading to CSLA 11.md are updated.

Test plan

  • csla.build.sln builds for all targets (netstandard2.0, net462 to net48, net10.0, net11.0).
  • New SafeDataReaderAsyncTests run against SQLite and pass on net10.0 and net11.0. They cover:
    • reading rows and moving between result sets;
    • typed values and the defaults returned for nulls;
    • cancellation;
    • CloseAsync and DisposeAsync;
    • the synchronous fallback for readers that aren't a DbDataReader.
  • Full csla.test.sln suite (TestCategory!=SkipOnCIServer) passes.

Closes #4975

🤖 Generated with Claude Code

rockfordlhotka and others added 2 commits October 30, 2026 11:17
SafeDataReader gets ReadAsync, NextResultAsync, CloseAsync,
IsDBNullAsync, GetFieldValueAsync<T>, null-safe async getters
(GetStringAsync, GetInt32Async and the rest) and DisposeAsync. They
use the underlying DbDataReader, and run synchronously when the
wrapped reader isn't one.

SafeSqlDataReader now inherits ReadAsync, NextResultAsync and
GetFieldValueAsync<T> from SafeDataReader, and IsDbNullAsync is
obsolete in favor of IsDBNullAsync.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Async disposal can skip subclasses’ unmanaged-resource cleanup, and the upgrade guide omits required source-compatibility changes.

2 open issues
What changed in this PR

Adds async support to CSLA’s SafeDataReader, addressing #4975 while preserving null-safe typed getters and synchronous fallback for readers that are not DbDataReader.

Changes:

  • Adds async navigation, value access, closing, and disposal.
  • Moves shared async methods from SafeSqlDataReader into the base reader and deprecates IsDbNullAsync.
  • Adds SQLite-backed tests and documents the new APIs and migration requirements.
File Description
Source/​tests/​Csla.test/​SafeDataReader/​SafeDataReaderAsyncTests.cs Tests async getters, navigation, cancellation, cleanup, and fallback behavior.
Source/​Csla/​Data/​SafeDataReader.cs Implements async reader APIs and IAsyncDisposable.
Source/​Csla.Data.SqlClient.Fx/​SafeSqlDataReader.cs Inherits shared async methods and retains obsolete null-check aliases.
releasenotes.md Announces async support and compatibility changes.
docs/​Upgrading to CSLA 11.md Provides usage examples and migration guidance.

Review effort: Balanced

Comment thread Source/Csla/Data/SafeDataReader.cs Resolved
Comment thread docs/Upgrading to CSLA 11.md Resolved
…(false) from DisposeAsync

Name the async ordinal parameters ordinal and give ReadAsync,
NextResultAsync, IsDBNullAsync(int) and GetFieldValueAsync<T>(int)
overloads with and without a CancellationToken, so code written
against SafeSqlDataReader still compiles. DisposeAsync now calls
Dispose(false) so subclass cleanup runs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rockfordlhotka
rockfordlhotka merged commit 1e55a04 into main Oct 30, 2026
3 checks passed
@rockfordlhotka
rockfordlhotka deleted the issue-4975/async-safedatareader branch October 30, 2026 16:49
Sign up for free to 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.

Async SafeDataReader

2 participants