Skip to content

Missing functionality in batch API #2222

Closed

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());

Activity

  1. mgravell commented on Nov 16, 2023

    @mgravell
    Author

    note that adding net8 triggers a few [Obsolete] warnings, CS0672; requires

    #if NET8_0_OR_GREATER
            [Obsolete]
    #endif
    

    on

    • SqlException.GetObjectData
    • SqlException.ctor(SerializationInfo, StreamingContext)
    • OperationAbortedException.ctor(SerializationInfo, StreamingContext)

    I also get a build error from Microsoft.Data.SqlClient.notsupported.cs via GenAPI; not sure what to do about that one, but: it needs fixing. It looks like the file gets regenerated on build, so manual hack may not be sufficient.

  2. Wraith2 commented on Nov 16, 2023

    @Wraith2
    Contributor

    I'll take a look.

  3. mgravell commented on Nov 16, 2023

    @mgravell
    Author

    awesome; I'll go ahead and do what I can with my locally hacked version that targets net7 with the first half of the fixes; I can't test the net8 parameter fix (because that single error is blocking the build), but... that's the small end of the wedge for this

  4. added
    Public API 🆕
    and removed on Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Public API 🆕

    Type

    No type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions