Skip to content

Commit

Permalink
normalize async API surface over all TFMs (#2144)
Browse files Browse the repository at this point in the history
* - normalize async API surface over all TFMs (fix #2143)
- target net8.0 instead of net5.0
- lib updates

* net9 SDK

* perf tests: clean up SqlClient warning

* CI fix: test concurrency

* rev snowflake
  • Loading branch information
mgravell authored Feb 6, 2025
1 parent 4e57602 commit bd4f75b
Show file tree
Hide file tree
Showing 34 changed files with 116 additions and 79 deletions.
2 changes: 1 addition & 1 deletion Dapper.ProviderTools/Dapper.ProviderTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Title>Dapper Provider Tools</Title>
<Description>Provider-agnostic ADO.NET helper utilities</Description>
<Authors>Marc Gravell</Authors>
<TargetFrameworks>net461;netstandard2.0;net5.0</TargetFrameworks>
<TargetFrameworks>net461;netstandard2.0;net8.0</TargetFrameworks>
<SignAssembly>true</SignAssembly>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion Dapper.SqlBuilder/Dapper.SqlBuilder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Title>Dapper SqlBuilder component</Title>
<Description>The Dapper SqlBuilder component, for building SQL queries dynamically.</Description>
<Authors>Sam Saffron, Johan Danforth</Authors>
<TargetFrameworks>net461;netstandard2.0;net5.0</TargetFrameworks>
<TargetFrameworks>net461;netstandard2.0;net8.0</TargetFrameworks>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<Nullable>enable</Nullable>
Expand Down
7 changes: 6 additions & 1 deletion Dapper.StrongName/Dapper.StrongName.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Title>Dapper (Strong Named)</Title>
<Description>A high performance Micro-ORM supporting SQL Server, MySQL, Sqlite, SqlCE, Firebird etc. Major Sponsor: Dapper Plus from ZZZ Projects.</Description>
<Authors>Sam Saffron;Marc Gravell;Nick Craver</Authors>
<TargetFrameworks>net461;netstandard2.0;net5.0;net7.0</TargetFrameworks>
<TargetFrameworks>net461;netstandard2.0;net8.0</TargetFrameworks>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<Nullable>enable</Nullable>
Expand All @@ -17,7 +17,12 @@
<Compile Include="..\Dapper\**\*.cs" Exclude="..\Dapper\obj\**\*.cs" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net461'">
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" />
<PackageReference Include="System.Reflection.Emit.Lightweight" />
</ItemGroup>
</Project>
7 changes: 6 additions & 1 deletion Dapper/Dapper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<PackageTags>orm;sql;micro-orm</PackageTags>
<Description>A high performance Micro-ORM supporting SQL Server, MySQL, Sqlite, SqlCE, Firebird etc. Major Sponsor: Dapper Plus from ZZZ Projects.</Description>
<Authors>Sam Saffron;Marc Gravell;Nick Craver</Authors>
<TargetFrameworks>net461;netstandard2.0;net5.0;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net461;netstandard2.0;net8.0</TargetFrameworks>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
Expand All @@ -24,7 +24,12 @@
</PackageReference>
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net461'">
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" />
<PackageReference Include="System.Reflection.Emit.Lightweight" />
</ItemGroup>
</Project>
5 changes: 5 additions & 0 deletions Dapper/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Dapper.SqlMapper.GridReader.CancellationToken.get -> System.Threading.Cancellati
Dapper.SqlMapper.GridReader.Command.get -> System.Data.IDbCommand!
Dapper.SqlMapper.GridReader.Command.set -> void
Dapper.SqlMapper.GridReader.Dispose() -> void
Dapper.SqlMapper.GridReader.DisposeAsync() -> System.Threading.Tasks.ValueTask
Dapper.SqlMapper.GridReader.GridReader(System.Data.IDbCommand! command, System.Data.Common.DbDataReader! reader, Dapper.SqlMapper.Identity? identity, System.Action<object?>? onCompleted = null, object? state = null, bool addToCache = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> void
Dapper.SqlMapper.GridReader.IsConsumed.get -> bool
Dapper.SqlMapper.GridReader.OnAfterGrid(int index) -> void
Expand Down Expand Up @@ -112,6 +113,8 @@ Dapper.SqlMapper.GridReader.ReadSingleOrDefault<T>() -> T?
Dapper.SqlMapper.GridReader.ReadSingleOrDefaultAsync() -> System.Threading.Tasks.Task<dynamic?>!
Dapper.SqlMapper.GridReader.ReadSingleOrDefaultAsync(System.Type! type) -> System.Threading.Tasks.Task<object?>!
Dapper.SqlMapper.GridReader.ReadSingleOrDefaultAsync<T>() -> System.Threading.Tasks.Task<T?>!
Dapper.SqlMapper.GridReader.ReadUnbufferedAsync() -> System.Collections.Generic.IAsyncEnumerable<dynamic!>!
Dapper.SqlMapper.GridReader.ReadUnbufferedAsync<T>() -> System.Collections.Generic.IAsyncEnumerable<T>!
Dapper.SqlMapper.GridReader.ResultIndex.get -> int
Dapper.SqlMapper.ICustomQueryParameter
Dapper.SqlMapper.ICustomQueryParameter.AddParameter(System.Data.IDbCommand! command, string! name) -> void
Expand Down Expand Up @@ -295,6 +298,8 @@ static Dapper.SqlMapper.QuerySingleOrDefaultAsync(this System.Data.IDbConnection
static Dapper.SqlMapper.QuerySingleOrDefaultAsync(this System.Data.IDbConnection! cnn, System.Type! type, string! sql, object? param = null, System.Data.IDbTransaction? transaction = null, int? commandTimeout = null, System.Data.CommandType? commandType = null) -> System.Threading.Tasks.Task<object?>!
static Dapper.SqlMapper.QuerySingleOrDefaultAsync<T>(this System.Data.IDbConnection! cnn, Dapper.CommandDefinition command) -> System.Threading.Tasks.Task<T?>!
static Dapper.SqlMapper.QuerySingleOrDefaultAsync<T>(this System.Data.IDbConnection! cnn, string! sql, object? param = null, System.Data.IDbTransaction? transaction = null, int? commandTimeout = null, System.Data.CommandType? commandType = null) -> System.Threading.Tasks.Task<T?>!
static Dapper.SqlMapper.QueryUnbufferedAsync(this System.Data.Common.DbConnection! cnn, string! sql, object? param = null, System.Data.Common.DbTransaction? transaction = null, int? commandTimeout = null, System.Data.CommandType? commandType = null) -> System.Collections.Generic.IAsyncEnumerable<dynamic!>!
static Dapper.SqlMapper.QueryUnbufferedAsync<T>(this System.Data.Common.DbConnection! cnn, string! sql, object? param = null, System.Data.Common.DbTransaction? transaction = null, int? commandTimeout = null, System.Data.CommandType? commandType = null) -> System.Collections.Generic.IAsyncEnumerable<T>!
static Dapper.SqlMapper.ReadChar(object! value) -> char
static Dapper.SqlMapper.ReadNullableChar(object! value) -> char?
static Dapper.SqlMapper.RemoveTypeMap(System.Type! type) -> void
Expand Down
6 changes: 0 additions & 6 deletions Dapper/PublicAPI/net5.0/PublicAPI.Shipped.txt

This file was deleted.

6 changes: 0 additions & 6 deletions Dapper/PublicAPI/net6.0/PublicAPI.Shipped.txt

This file was deleted.

1 change: 0 additions & 1 deletion Dapper/PublicAPI/net6.0/PublicAPI.Unshipped.txt

This file was deleted.

6 changes: 0 additions & 6 deletions Dapper/PublicAPI/net7.0/PublicAPI.Shipped.txt

This file was deleted.

1 change: 0 additions & 1 deletion Dapper/PublicAPI/net7.0/PublicAPI.Unshipped.txt

This file was deleted.

1 change: 1 addition & 0 deletions Dapper/PublicAPI/net8.0/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#nullable enable
6 changes: 4 additions & 2 deletions Dapper/SqlMapper.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,6 @@ private static async Task<DbDataReader> ExecuteWrappedReaderImplAsync(IDbConnect
return Parse<T>(result);
}

#if NET5_0_OR_GREATER
/// <summary>
/// Execute a query asynchronously using <see cref="IAsyncEnumerable{dynamic}"/>.
/// </summary>
Expand Down Expand Up @@ -1338,12 +1337,15 @@ static async IAsyncEnumerable<T> Impl(IDbConnection cnn, Type effectiveType, Com
try { cmd?.Cancel(); }
catch { /* don't spoil any existing exception */ }
}
#if NET5_0_OR_GREATER
await reader.DisposeAsync();
#else
reader.Dispose();
#endif
}
if (wasClosed) cnn.Close();
}
}
}
#endif
}
}
19 changes: 11 additions & 8 deletions Dapper/SqlMapper.GridReader.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ namespace Dapper
public static partial class SqlMapper
{
public partial class GridReader
#if NET5_0_OR_GREATER
: IAsyncDisposable
#endif
{
/// <summary>
/// Read the next grid of results, returned as a dynamic object
Expand Down Expand Up @@ -161,11 +159,8 @@ protected async Task OnAfterGridAsync(int index)
#endif
reader = null!;
onCompleted?.Invoke(state);
#if NET5_0_OR_GREATER

await DisposeAsync();
#else
Dispose();
#endif
}
}

Expand Down Expand Up @@ -247,7 +242,6 @@ private async Task<IEnumerable<T>> ReadBufferedAsync<T>(int index, Func<DbDataRe
}
}

#if NET5_0_OR_GREATER
/// <summary>
/// Read the next grid of results.
/// </summary>
Expand Down Expand Up @@ -283,19 +277,29 @@ private async IAsyncEnumerable<T> ReadUnbufferedAsync<T>(int index, Func<DbDataR
/// <summary>
/// Dispose the grid, closing and disposing both the underlying reader and command.
/// </summary>
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously - for netfx version
public async ValueTask DisposeAsync()
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
{
if (reader is not null)
{
if (!reader.IsClosed) Command?.Cancel();
#if NET5_0_OR_GREATER
await reader.DisposeAsync();
#else
reader.Dispose();
#endif
reader = null!;
}
if (Command is not null)
{
if (Command is DbCommand typed)
{
#if NET5_0_OR_GREATER
await typed.DisposeAsync();
#else
typed.Dispose();
#endif
}
else
{
Expand All @@ -305,7 +309,6 @@ public async ValueTask DisposeAsync()
}
GC.SuppressFinalize(this);
}
#endif
}
}
}
3 changes: 2 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
<IncludeSymbols>false</IncludeSymbols>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<LangVersion>12</LangVersion>
<LangVersion>13</LangVersion>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
<PackageReadmeFile>readme.md</PackageReadmeFile>
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
Expand Down
37 changes: 19 additions & 18 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,46 @@
<PackageVersion Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="Microsoft.SqlServer.Types" Version="14.0.1016.290" />
<PackageVersion Include="Nerdbank.GitVersioning" Version="3.6.143" />
<PackageVersion Include="Nerdbank.GitVersioning" Version="3.7.115" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="9.0.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4" />
<PackageVersion Include="System.Reflection.Emit.Lightweight" Version="4.7.0" />
<!-- tests -->
<PackageVersion Include="Azure.Identity" Version="1.12.1" />
<PackageVersion Include="Azure.Identity" Version="1.13.2" />
<PackageVersion Include="Belgrade.Sql.Client" Version="1.1.4" />
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" />
<PackageVersion Include="Dashing" Version="2.10.1" />
<PackageVersion Include="Dapper.Contrib" Version="2.0.78" />
<PackageVersion Include="DuckDB.NET.Data.Full" Version="1.1.1" />
<PackageVersion Include="DevExpress.Xpo" Version="24.1.6" />
<PackageVersion Include="FirebirdSql.Data.FirebirdClient" Version="10.3.1" />
<PackageVersion Include="DuckDB.NET.Data.Full" Version="1.1.3" />
<PackageVersion Include="DevExpress.Xpo" Version="24.2.3" />
<PackageVersion Include="FirebirdSql.Data.FirebirdClient" Version="10.3.2" />
<PackageVersion Include="GitHubActionsTestLogger" Version="2.4.1" />
<PackageVersion Include="Iesi.Collections" Version="4.1.1" />
<PackageVersion Include="linq2db.SqlServer" Version="5.4.1" />
<PackageVersion Include="Microsoft.Data.SqlClient" Version="5.2.2" />
<PackageVersion Include="Microsoft.Data.Sqlite" Version="8.0.8" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.8" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="Mighty" Version="3.2.0" />
<PackageVersion Include="MySqlConnector" Version="2.3.7" />
<PackageVersion Include="Microsoft.Data.SqlClient" Version="6.0.1" />
<PackageVersion Include="Microsoft.Data.Sqlite" Version="9.0.1" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageVersion Include="Mighty" Version="3.3.0" />
<PackageVersion Include="MySqlConnector" Version="2.4.0" />
<PackageVersion Include="NHibernate" Version="5.5.2" />
<PackageVersion Include="Norm.net" Version="5.4.0" />
<PackageVersion Include="Npgsql" Version="8.0.4" />
<PackageVersion Include="Npgsql" Version="9.0.2" />
<PackageVersion Include="PetaPoco" Version="5.1.306" />
<PackageVersion Include="RepoDb.SqlServer" Version="1.13.1" />
<PackageVersion Include="ServiceStack.OrmLite.SqlServer" Version="8.4.0" />
<PackageVersion Include="Snowflake.Data" Version="4.1.0" />
<PackageVersion Include="ServiceStack.OrmLite.SqlServer" Version="8.5.2" />
<PackageVersion Include="Snowflake.Data" Version="4.3.0" />
<PackageVersion Include="SqlMarshal" Version="0.5.0" />
<PackageVersion Include="SubSonic" Version="3.0.0.4" />
<PackageVersion Include="Susanoo.SqlServer" Version="1.2.4.2" />
<PackageVersion Include="System.Data.SqlClient" Version="4.8.6" />
<PackageVersion Include="System.Data.SqlClient" Version="4.9.0" />
<PackageVersion Include="System.Data.SQLite" Version="1.0.119" />
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
<PackageVersion Include="System.Private.Uri" Version="4.3.2" />
<PackageVersion Include="System.Reflection.Metadata" Version="8.0.0" />
<PackageVersion Include="System.Reflection.Metadata" Version="9.0.1" />
<PackageVersion Include="System.Text.RegularExpressions" Version="4.3.1" />
<PackageVersion Include="System.ValueTuple" Version="4.5.0" />
<PackageVersion Include="xunit" Version="2.9.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
<PackageVersion Include="xunit" Version="2.9.3" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.1" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ skip_commits:
files:
- '**/*.md'

# install:
# - choco install dotnet-sdk --version 8.0.100
install:
- choco install dotnet-sdk --version 9.0.101

environment:
Appveyor: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;

namespace Dapper.Tests.Performance
{
Expand Down
8 changes: 4 additions & 4 deletions benchmarks/Dapper.Tests.Performance/Benchmarks.RepoDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public void Setup()
// We need this since benchmarks using System.Data.SqlClient
var dbSetting = new SqlServerDbSetting();
DbSettingMapper
.Add<System.Data.SqlClient.SqlConnection>(dbSetting, true);
.Add<Microsoft.Data.SqlClient.SqlConnection>(dbSetting, true);
DbHelperMapper
.Add<System.Data.SqlClient.SqlConnection>(new SqlServerDbHelper(), true);
.Add<Microsoft.Data.SqlClient.SqlConnection>(new SqlServerDbHelper(), true);
StatementBuilderMapper
.Add<System.Data.SqlClient.SqlConnection>(new SqlServerStatementBuilder(dbSetting), true);
.Add<Microsoft.Data.SqlClient.SqlConnection>(new SqlServerStatementBuilder(dbSetting), true);

ClassMapper.Add<Post>("Posts");
}
Expand Down Expand Up @@ -54,7 +54,7 @@ public Post QueryDynamic()
public Post QueryField()
{
Step();
return _connection.Query<Post>(new QueryField[] { new(nameof(Post.Id), i) }).First();
return _connection.Query<Post>([new(nameof(Post.Id), i)]).First();
}

[Benchmark(Description = "ExecuteQuery<T>")]
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/Dapper.Tests.Performance/Benchmarks.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using BenchmarkDotNet.Attributes;
using System;
using System.Configuration;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;

namespace Dapper.Tests.Performance
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,22 @@
<PackageReference Include="NHibernate" />
<PackageReference Include="Iesi.Collections" />
<PackageReference Include="Mighty" />
<PackageReference Include="Npgsql" />
<PackageReference Include="PetaPoco" />
<PackageReference Include="RepoDb.SqlServer" />
<PackageReference Include="ServiceStack.OrmLite.SqlServer" />
<PackageReference Include="SqlMarshal" />
<PackageReference Include="System.Data.SqlClient" />
<PackageReference Include="System.Data.SQLite" />
<PackageReference Include="System.Reflection.Metadata" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' != 'net462'">
<PackageReference Include="Npgsql" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net462'">
<PackageReference Include="Npgsql" VersionOverride="8.0.6"/>
</ItemGroup>

<ItemGroup>
<!-- NU1903 warnings -->
<PackageReference Include="System.Text.RegularExpressions" />
Expand Down
Loading

0 comments on commit bd4f75b

Please sign in to comment.