Skip to content

Missing functionality in batch API #2222

@mgravell

Description

@mgravell

Relates to #1825

Testing local build (main) with Dapper shows a few problems, i.e. "it doesn't work"; severity: IMO critical, this should absolutely be fixed before next build; the batch API is not usable by non-provider scenarios without it

  1. SqlConnection fails to override the CanCreateBatch and CreateDbBatch() members (net6+)
  2. SqlBatchCommand does override the CanCreateParameter and CreateParameter() members (net8+), but: the library does not currently build for net8, so: this code is never actually compiled as far as I can see

Suggestions:

for SqlConnection:

#if NET6_0_OR_GREATER
        /// <inheritdoc/>
        public override bool CanCreateBatch => true;

        /// <inheritdoc/>
        protected override SqlBatch CreateDbBatch() => new SqlBatch(this);
#endif

(you may have local rules on docs, especially since we're doing type variance here)


in the csproj:

  • add net8.0 to <TargetFrameworks>

tests:

for net6+

using var cnn = new SqlConnection();
Assert.True(cnn.CanCreateBatch);
var batch = cnn.CreateBatch();
Assert.Is<SqlBatch>(batch);
Assert.Same(cnn, batch.Connection);
Assert.Null(batch.Transaction);

for net8+

var cmd = new SqlBatchCommand();
Assert.True(cnn.CanCreateParameter);
Assert.Is<SqlParameter>(cnn.CreateParameter());

Metadata

Metadata

Assignees

No one assigned

    Labels

    Public API 🆕Issues/PRs that introduce new APIs to the driver.

    Type

    No type

    Projects

    Status

    Closed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions