From c03c5e9d1336dc533ca2b2b532e4ba7d49015926 Mon Sep 17 00:00:00 2001 From: Marc Gravell Date: Sat, 25 Jan 2025 14:48:12 +0000 Subject: [PATCH 1/5] - normalize async API surface over all TFMs (fix #2143) - target net8.0 instead of net5.0 - lib updates --- .../Dapper.ProviderTools.csproj | 2 +- Dapper.SqlBuilder/Dapper.SqlBuilder.csproj | 2 +- Dapper.StrongName/Dapper.StrongName.csproj | 7 +++- Dapper/Dapper.csproj | 7 +++- Dapper/PublicAPI.Shipped.txt | 5 +++ Dapper/PublicAPI/net5.0/PublicAPI.Shipped.txt | 6 --- Dapper/PublicAPI/net6.0/PublicAPI.Shipped.txt | 6 --- .../PublicAPI/net6.0/PublicAPI.Unshipped.txt | 1 - Dapper/PublicAPI/net7.0/PublicAPI.Shipped.txt | 6 --- .../PublicAPI/net7.0/PublicAPI.Unshipped.txt | 1 - Dapper/PublicAPI/net8.0/PublicAPI.Shipped.txt | 1 + .../PublicAPI.Unshipped.txt | 0 Dapper/SqlMapper.Async.cs | 6 ++- Dapper/SqlMapper.GridReader.Async.cs | 19 ++++++---- Directory.Build.props | 1 + Directory.Packages.props | 37 ++++++++++--------- .../Dapper.Tests.Performance.csproj | 10 ++++- tests/Dapper.Tests/AsyncTests.cs | 2 - tests/Dapper.Tests/Dapper.Tests.csproj | 16 +++++--- tests/Dapper.Tests/DateTimeOnlyTests.cs | 2 +- tests/Dapper.Tests/Helpers/IsExternalInit.cs | 7 ++++ tests/Dapper.Tests/ParameterTests.cs | 13 +++++++ tests/Dapper.Tests/ProviderTests.cs | 2 + .../Dapper.Tests/Providers/SnowflakeTests.cs | 2 +- tests/Dapper.Tests/SingleRowTests.cs | 4 +- tests/Dapper.Tests/TestBase.cs | 2 + 26 files changed, 101 insertions(+), 66 deletions(-) delete mode 100644 Dapper/PublicAPI/net5.0/PublicAPI.Shipped.txt delete mode 100644 Dapper/PublicAPI/net6.0/PublicAPI.Shipped.txt delete mode 100644 Dapper/PublicAPI/net6.0/PublicAPI.Unshipped.txt delete mode 100644 Dapper/PublicAPI/net7.0/PublicAPI.Shipped.txt delete mode 100644 Dapper/PublicAPI/net7.0/PublicAPI.Unshipped.txt create mode 100644 Dapper/PublicAPI/net8.0/PublicAPI.Shipped.txt rename Dapper/PublicAPI/{net5.0 => net8.0}/PublicAPI.Unshipped.txt (100%) create mode 100644 tests/Dapper.Tests/Helpers/IsExternalInit.cs diff --git a/Dapper.ProviderTools/Dapper.ProviderTools.csproj b/Dapper.ProviderTools/Dapper.ProviderTools.csproj index 61e8b4c58..176887317 100644 --- a/Dapper.ProviderTools/Dapper.ProviderTools.csproj +++ b/Dapper.ProviderTools/Dapper.ProviderTools.csproj @@ -5,7 +5,7 @@ Dapper Provider Tools Provider-agnostic ADO.NET helper utilities Marc Gravell - net461;netstandard2.0;net5.0 + net461;netstandard2.0;net8.0 true enable diff --git a/Dapper.SqlBuilder/Dapper.SqlBuilder.csproj b/Dapper.SqlBuilder/Dapper.SqlBuilder.csproj index b597bd9eb..c101afcaa 100644 --- a/Dapper.SqlBuilder/Dapper.SqlBuilder.csproj +++ b/Dapper.SqlBuilder/Dapper.SqlBuilder.csproj @@ -5,7 +5,7 @@ Dapper SqlBuilder component The Dapper SqlBuilder component, for building SQL queries dynamically. Sam Saffron, Johan Danforth - net461;netstandard2.0;net5.0 + net461;netstandard2.0;net8.0 false false enable diff --git a/Dapper.StrongName/Dapper.StrongName.csproj b/Dapper.StrongName/Dapper.StrongName.csproj index 770b7ce7a..f202f8f6c 100644 --- a/Dapper.StrongName/Dapper.StrongName.csproj +++ b/Dapper.StrongName/Dapper.StrongName.csproj @@ -5,7 +5,7 @@ Dapper (Strong Named) A high performance Micro-ORM supporting SQL Server, MySQL, Sqlite, SqlCE, Firebird etc. Major Sponsor: Dapper Plus from ZZZ Projects. Sam Saffron;Marc Gravell;Nick Craver - net461;netstandard2.0;net5.0;net7.0 + net461;netstandard2.0;net8.0 true true enable @@ -17,7 +17,12 @@ + + + + + diff --git a/Dapper/Dapper.csproj b/Dapper/Dapper.csproj index 28951f871..af5febfb8 100644 --- a/Dapper/Dapper.csproj +++ b/Dapper/Dapper.csproj @@ -5,7 +5,7 @@ orm;sql;micro-orm A high performance Micro-ORM supporting SQL Server, MySQL, Sqlite, SqlCE, Firebird etc. Major Sponsor: Dapper Plus from ZZZ Projects. Sam Saffron;Marc Gravell;Nick Craver - net461;netstandard2.0;net5.0;net6.0;net7.0 + net461;netstandard2.0;net8.0 enable true @@ -24,7 +24,12 @@ + + + + + diff --git a/Dapper/PublicAPI.Shipped.txt b/Dapper/PublicAPI.Shipped.txt index c1b08ea99..456aa8bb1 100644 --- a/Dapper/PublicAPI.Shipped.txt +++ b/Dapper/PublicAPI.Shipped.txt @@ -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? 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 @@ -112,6 +113,8 @@ Dapper.SqlMapper.GridReader.ReadSingleOrDefault() -> T? Dapper.SqlMapper.GridReader.ReadSingleOrDefaultAsync() -> System.Threading.Tasks.Task! Dapper.SqlMapper.GridReader.ReadSingleOrDefaultAsync(System.Type! type) -> System.Threading.Tasks.Task! Dapper.SqlMapper.GridReader.ReadSingleOrDefaultAsync() -> System.Threading.Tasks.Task! +Dapper.SqlMapper.GridReader.ReadUnbufferedAsync() -> System.Collections.Generic.IAsyncEnumerable! +Dapper.SqlMapper.GridReader.ReadUnbufferedAsync() -> System.Collections.Generic.IAsyncEnumerable! Dapper.SqlMapper.GridReader.ResultIndex.get -> int Dapper.SqlMapper.ICustomQueryParameter Dapper.SqlMapper.ICustomQueryParameter.AddParameter(System.Data.IDbCommand! command, string! name) -> void @@ -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! static Dapper.SqlMapper.QuerySingleOrDefaultAsync(this System.Data.IDbConnection! cnn, Dapper.CommandDefinition command) -> System.Threading.Tasks.Task! static Dapper.SqlMapper.QuerySingleOrDefaultAsync(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! +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! +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! static Dapper.SqlMapper.ReadChar(object! value) -> char static Dapper.SqlMapper.ReadNullableChar(object! value) -> char? static Dapper.SqlMapper.RemoveTypeMap(System.Type! type) -> void diff --git a/Dapper/PublicAPI/net5.0/PublicAPI.Shipped.txt b/Dapper/PublicAPI/net5.0/PublicAPI.Shipped.txt deleted file mode 100644 index 5da46e604..000000000 --- a/Dapper/PublicAPI/net5.0/PublicAPI.Shipped.txt +++ /dev/null @@ -1,6 +0,0 @@ -#nullable enable -Dapper.SqlMapper.GridReader.DisposeAsync() -> System.Threading.Tasks.ValueTask -Dapper.SqlMapper.GridReader.ReadUnbufferedAsync() -> System.Collections.Generic.IAsyncEnumerable! -Dapper.SqlMapper.GridReader.ReadUnbufferedAsync() -> System.Collections.Generic.IAsyncEnumerable! -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! -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! \ No newline at end of file diff --git a/Dapper/PublicAPI/net6.0/PublicAPI.Shipped.txt b/Dapper/PublicAPI/net6.0/PublicAPI.Shipped.txt deleted file mode 100644 index 5da46e604..000000000 --- a/Dapper/PublicAPI/net6.0/PublicAPI.Shipped.txt +++ /dev/null @@ -1,6 +0,0 @@ -#nullable enable -Dapper.SqlMapper.GridReader.DisposeAsync() -> System.Threading.Tasks.ValueTask -Dapper.SqlMapper.GridReader.ReadUnbufferedAsync() -> System.Collections.Generic.IAsyncEnumerable! -Dapper.SqlMapper.GridReader.ReadUnbufferedAsync() -> System.Collections.Generic.IAsyncEnumerable! -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! -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! \ No newline at end of file diff --git a/Dapper/PublicAPI/net6.0/PublicAPI.Unshipped.txt b/Dapper/PublicAPI/net6.0/PublicAPI.Unshipped.txt deleted file mode 100644 index 91b0e1a43..000000000 --- a/Dapper/PublicAPI/net6.0/PublicAPI.Unshipped.txt +++ /dev/null @@ -1 +0,0 @@ -#nullable enable \ No newline at end of file diff --git a/Dapper/PublicAPI/net7.0/PublicAPI.Shipped.txt b/Dapper/PublicAPI/net7.0/PublicAPI.Shipped.txt deleted file mode 100644 index 5da46e604..000000000 --- a/Dapper/PublicAPI/net7.0/PublicAPI.Shipped.txt +++ /dev/null @@ -1,6 +0,0 @@ -#nullable enable -Dapper.SqlMapper.GridReader.DisposeAsync() -> System.Threading.Tasks.ValueTask -Dapper.SqlMapper.GridReader.ReadUnbufferedAsync() -> System.Collections.Generic.IAsyncEnumerable! -Dapper.SqlMapper.GridReader.ReadUnbufferedAsync() -> System.Collections.Generic.IAsyncEnumerable! -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! -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! \ No newline at end of file diff --git a/Dapper/PublicAPI/net7.0/PublicAPI.Unshipped.txt b/Dapper/PublicAPI/net7.0/PublicAPI.Unshipped.txt deleted file mode 100644 index 91b0e1a43..000000000 --- a/Dapper/PublicAPI/net7.0/PublicAPI.Unshipped.txt +++ /dev/null @@ -1 +0,0 @@ -#nullable enable \ No newline at end of file diff --git a/Dapper/PublicAPI/net8.0/PublicAPI.Shipped.txt b/Dapper/PublicAPI/net8.0/PublicAPI.Shipped.txt new file mode 100644 index 000000000..ab058de62 --- /dev/null +++ b/Dapper/PublicAPI/net8.0/PublicAPI.Shipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/Dapper/PublicAPI/net5.0/PublicAPI.Unshipped.txt b/Dapper/PublicAPI/net8.0/PublicAPI.Unshipped.txt similarity index 100% rename from Dapper/PublicAPI/net5.0/PublicAPI.Unshipped.txt rename to Dapper/PublicAPI/net8.0/PublicAPI.Unshipped.txt diff --git a/Dapper/SqlMapper.Async.cs b/Dapper/SqlMapper.Async.cs index 9408d5735..fb7ce448c 100644 --- a/Dapper/SqlMapper.Async.cs +++ b/Dapper/SqlMapper.Async.cs @@ -1249,7 +1249,6 @@ private static async Task ExecuteWrappedReaderImplAsync(IDbConnect return Parse(result); } -#if NET5_0_OR_GREATER /// /// Execute a query asynchronously using . /// @@ -1338,12 +1337,15 @@ static async IAsyncEnumerable 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 } } diff --git a/Dapper/SqlMapper.GridReader.Async.cs b/Dapper/SqlMapper.GridReader.Async.cs index 5b5b9b73d..a32d53124 100644 --- a/Dapper/SqlMapper.GridReader.Async.cs +++ b/Dapper/SqlMapper.GridReader.Async.cs @@ -10,9 +10,7 @@ namespace Dapper public static partial class SqlMapper { public partial class GridReader -#if NET5_0_OR_GREATER : IAsyncDisposable -#endif { /// /// Read the next grid of results, returned as a dynamic object @@ -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 } } @@ -247,7 +242,6 @@ private async Task> ReadBufferedAsync(int index, Func /// Read the next grid of results. /// @@ -283,19 +277,29 @@ private async IAsyncEnumerable ReadUnbufferedAsync(int index, Func /// Dispose the grid, closing and disposing both the underlying reader and command. /// +#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 { @@ -305,7 +309,6 @@ public async ValueTask DisposeAsync() } GC.SuppressFinalize(this); } -#endif } } } diff --git a/Directory.Build.props b/Directory.Build.props index 6a4b94e1c..99e65b105 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -25,6 +25,7 @@ false true readme.md + true diff --git a/Directory.Packages.props b/Directory.Packages.props index 4cc865132..e85a64ccf 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -7,45 +7,46 @@ - + + - + - - - + + + - - - - - - + + + + + + - + - - + + - + - + - - + + \ No newline at end of file diff --git a/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj b/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj index dd0269a0d..fa18bd9c5 100644 --- a/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj +++ b/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj @@ -21,16 +21,22 @@ - - + + + + + + + + diff --git a/tests/Dapper.Tests/AsyncTests.cs b/tests/Dapper.Tests/AsyncTests.cs index a2f214b42..ec83dc2d9 100644 --- a/tests/Dapper.Tests/AsyncTests.cs +++ b/tests/Dapper.Tests/AsyncTests.cs @@ -46,7 +46,6 @@ public async Task TestBasicStringUsageAsync() Assert.Equal(new[] { "abc", "def" }, arr); } -#if NET5_0_OR_GREATER [Fact] public async Task TestBasicStringUsageUnbufferedDynamicAsync() { @@ -158,7 +157,6 @@ public async Task TestBasicStringUsageViaGridReaderUnbufferedAsync_Cancellation( var arr = results.ToArray(); Assert.Equal(new[] { "abc", "def" }, arr); // don't expect the ghi because of cancellation } -#endif [Fact] public async Task TestBasicStringUsageQueryFirstAsync() diff --git a/tests/Dapper.Tests/Dapper.Tests.csproj b/tests/Dapper.Tests/Dapper.Tests.csproj index f370ebbcc..4c242bf81 100644 --- a/tests/Dapper.Tests/Dapper.Tests.csproj +++ b/tests/Dapper.Tests/Dapper.Tests.csproj @@ -2,17 +2,17 @@ Dapper.Tests Dapper Core Test Suite - net472;net6.0;net8.0 + net481;net8.0;net9.0 $(DefineConstants);MSSQLCLIENT $(NoWarn);IDE0017;IDE0034;IDE0037;IDE0039;IDE0042;IDE0044;IDE0051;IDE0052;IDE0059;IDE0060;IDE0063;IDE1006;xUnit1004;CA1806;CA1816;CA1822;CA1825;CA2208;CA1861 enable true - + $(DefineConstants);ENTITY_FRAMEWORK;LINQ2SQL;OLEDB - + @@ -22,16 +22,20 @@ - - + + - + + + + + diff --git a/tests/Dapper.Tests/DateTimeOnlyTests.cs b/tests/Dapper.Tests/DateTimeOnlyTests.cs index 68e8bc170..cabad699d 100644 --- a/tests/Dapper.Tests/DateTimeOnlyTests.cs +++ b/tests/Dapper.Tests/DateTimeOnlyTests.cs @@ -17,7 +17,7 @@ public abstract class DateTimeOnlyTests : TestBase where T { public class HazDateTimeOnly { - public string Name { get; set; } + public string Name { get; set; } = ""; public DateOnly Date { get; set; } public TimeOnly Time { get; set; } public DateOnly? NDate { get; set; } diff --git a/tests/Dapper.Tests/Helpers/IsExternalInit.cs b/tests/Dapper.Tests/Helpers/IsExternalInit.cs new file mode 100644 index 000000000..7a67b19de --- /dev/null +++ b/tests/Dapper.Tests/Helpers/IsExternalInit.cs @@ -0,0 +1,7 @@ +namespace System.Runtime.CompilerServices; + +#if !NET5_0_OR_GREATER +internal static class IsExternalInit +{ +} +#endif diff --git a/tests/Dapper.Tests/ParameterTests.cs b/tests/Dapper.Tests/ParameterTests.cs index b6408359e..a5e3c4420 100644 --- a/tests/Dapper.Tests/ParameterTests.cs +++ b/tests/Dapper.Tests/ParameterTests.cs @@ -61,16 +61,22 @@ public void AddParameter(IDbCommand command, string name) private static IEnumerable CreateSqlDataRecordList(IDbCommand command, IEnumerable numbers) { +#pragma warning disable CS0618 // Type or member is obsolete if (command is System.Data.SqlClient.SqlCommand) return CreateSqlDataRecordList_SD(numbers); +#pragma warning restore CS0618 // Type or member is obsolete if (command is Microsoft.Data.SqlClient.SqlCommand) return CreateSqlDataRecordList_MD(numbers); throw new ArgumentException(nameof(command)); } private static IEnumerable CreateSqlDataRecordList(IDbConnection connection, IEnumerable numbers) { +#pragma warning disable CS0618 // Type or member is obsolete if (connection is System.Data.SqlClient.SqlConnection) return CreateSqlDataRecordList_SD(numbers); +#pragma warning restore CS0618 // Type or member is obsolete if (connection is Microsoft.Data.SqlClient.SqlConnection) return CreateSqlDataRecordList_MD(numbers); throw new ArgumentException(nameof(connection)); } + +#pragma warning disable CS0618 // Type or member is obsolete private static List CreateSqlDataRecordList_SD(IEnumerable numbers) { var number_list = new List(); @@ -88,6 +94,7 @@ private static IEnumerable CreateSqlDataRecordList(IDbConnection co return number_list; } +#pragma warning restore CS0618 // Type or member is obsolete private static List CreateSqlDataRecordList_MD(IEnumerable numbers) { @@ -147,6 +154,7 @@ public void AddParameter(IDbCommand command, string name) private static IDbDataParameter AddStructured(IDbCommand command, object value) { +#pragma warning disable CS0618 // Type or member is obsolete if (command is System.Data.SqlClient.SqlCommand sdcmd) { var p = sdcmd.Parameters.Add("integers", SqlDbType.Structured); @@ -155,6 +163,7 @@ private static IDbDataParameter AddStructured(IDbCommand command, object value) p.Value = value; return p; } +#pragma warning restore CS0618 // Type or member is obsolete else if (command is Microsoft.Data.SqlClient.SqlCommand mdcmd) { var p = mdcmd.Parameters.Add("integers", SqlDbType.Structured); @@ -497,11 +506,13 @@ public void TestSqlDataRecordListParametersWithTypeHandlers() // Variable type has to be IEnumerable for TypeHandler to kick in. object args; +#pragma warning disable CS0618 // Type or member is obsolete if (connection is System.Data.SqlClient.SqlConnection) { IEnumerable records = CreateSqlDataRecordList_SD(new int[] { 1, 2, 3 }); args = new { integers = records }; } +#pragma warning restore CS0618 // Type or member is obsolete else if (connection is Microsoft.Data.SqlClient.SqlConnection) { IEnumerable records = CreateSqlDataRecordList_MD(new int[] { 1, 2, 3 }); @@ -1655,10 +1666,12 @@ Id int not null primary key identity(1,1), { recvValue = msReader.GetSqlDecimal(1); } +#pragma warning disable CS0618 // Type or member is obsolete else if (reader is System.Data.SqlClient.SqlDataReader sdReader) { recvValue = sdReader.GetSqlDecimal(1); } +#pragma warning restore CS0618 // Type or member is obsolete else { throw new InvalidOperationException($"unexpected reader type: {reader.GetType().FullName}"); diff --git a/tests/Dapper.Tests/ProviderTests.cs b/tests/Dapper.Tests/ProviderTests.cs index e3a553c5f..c0f2d58f2 100644 --- a/tests/Dapper.Tests/ProviderTests.cs +++ b/tests/Dapper.Tests/ProviderTests.cs @@ -10,8 +10,10 @@ public class ProviderTests [Fact] public void BulkCopy_SystemDataSqlClient() { +#pragma warning disable CS0618 // Type or member is obsolete using var conn = new System.Data.SqlClient.SqlConnection(); Test(conn); +#pragma warning restore CS0618 // Type or member is obsolete } [Fact] diff --git a/tests/Dapper.Tests/Providers/SnowflakeTests.cs b/tests/Dapper.Tests/Providers/SnowflakeTests.cs index 64b2d11f7..610592461 100644 --- a/tests/Dapper.Tests/Providers/SnowflakeTests.cs +++ b/tests/Dapper.Tests/Providers/SnowflakeTests.cs @@ -1,4 +1,4 @@ -#if !NET462 // platform not supported exception +#if !NETFRAMEWORK // platform not supported exception using System; using System.Collections.Generic; using System.IO; diff --git a/tests/Dapper.Tests/SingleRowTests.cs b/tests/Dapper.Tests/SingleRowTests.cs index a26d757f8..ab554514f 100644 --- a/tests/Dapper.Tests/SingleRowTests.cs +++ b/tests/Dapper.Tests/SingleRowTests.cs @@ -18,7 +18,9 @@ public sealed class SystemSqlClientSingleRowTests(ITestOutputHelper log) : Singl { protected override async Task InjectDataAsync(DbConnection conn, DbDataReader source) { +#pragma warning disable CS0618 // Type or member is obsolete using var bcp = new System.Data.SqlClient.SqlBulkCopy((System.Data.SqlClient.SqlConnection)conn); +#pragma warning restore CS0618 // Type or member is obsolete bcp.DestinationTableName = "#mydata"; bcp.EnableStreaming = true; await bcp.WriteToServerAsync(source); @@ -107,12 +109,10 @@ public async Task QueryFirst_PerformanceAndCorrectness() watch.Stop(); log.WriteLine($"sync unbuffered LINQ read first complete; row {row.Id} in {watch.ElapsedMilliseconds}ms"); -#if NET5_0_OR_GREATER watch = Stopwatch.StartNew(); row = await conn.QueryUnbufferedAsync("select * from #mydata").FirstAsync(); watch.Stop(); log.WriteLine($"async unbuffered LINQ read first complete; row {row.Id} in {watch.ElapsedMilliseconds}ms"); -#endif static unsafe string CreateName(Random rand) { diff --git a/tests/Dapper.Tests/TestBase.cs b/tests/Dapper.Tests/TestBase.cs index 7c7b2920f..e5e2c6560 100644 --- a/tests/Dapper.Tests/TestBase.cs +++ b/tests/Dapper.Tests/TestBase.cs @@ -74,7 +74,9 @@ public DbConnection GetOpenConnection(bool mars) } public sealed class SystemSqlClientProvider : SqlServerDatabaseProvider { +#pragma warning disable CS0618 // Type or member is obsolete public override DbProviderFactory Factory => System.Data.SqlClient.SqlClientFactory.Instance; +#pragma warning restore CS0618 // Type or member is obsolete } #if MSSQLCLIENT public sealed class MicrosoftSqlClientProvider : SqlServerDatabaseProvider From 7a653ba260340c2b6144eb29b990405a52fa4caa Mon Sep 17 00:00:00 2001 From: Marc Gravell Date: Sat, 25 Jan 2025 17:57:49 +0000 Subject: [PATCH 2/5] net9 SDK --- Directory.Build.props | 2 +- appveyor.yml | 4 ++-- global.json | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 99e65b105..cb8af4d2d 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -21,7 +21,7 @@ false true true - 12 + 13 false true readme.md diff --git a/appveyor.yml b/appveyor.yml index ca2e79161..8c1e48d84 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -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 diff --git a/global.json b/global.json index 7da276347..2cbaab19b 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "8.0.100", + "version": "9.0.101", "rollForward": "latestMajor" } } \ No newline at end of file From 12766425197dc2adee1e55d98fca152883edfa33 Mon Sep 17 00:00:00 2001 From: Marc Gravell Date: Sat, 25 Jan 2025 18:15:23 +0000 Subject: [PATCH 3/5] perf tests: clean up SqlClient warning --- .../Dapper.Tests.Performance/Benchmarks.HandCoded.cs | 2 +- benchmarks/Dapper.Tests.Performance/Benchmarks.RepoDB.cs | 8 ++++---- benchmarks/Dapper.Tests.Performance/Benchmarks.cs | 2 +- benchmarks/Dapper.Tests.Performance/LegacyTests.cs | 2 +- benchmarks/Dapper.Tests.Performance/Program.cs | 2 +- .../Dapper.Tests.Performance/SqlDataReaderHelper.cs | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/benchmarks/Dapper.Tests.Performance/Benchmarks.HandCoded.cs b/benchmarks/Dapper.Tests.Performance/Benchmarks.HandCoded.cs index 05013e465..3fcfc6d3d 100644 --- a/benchmarks/Dapper.Tests.Performance/Benchmarks.HandCoded.cs +++ b/benchmarks/Dapper.Tests.Performance/Benchmarks.HandCoded.cs @@ -2,7 +2,7 @@ using System; using System.ComponentModel; using System.Data; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; namespace Dapper.Tests.Performance { diff --git a/benchmarks/Dapper.Tests.Performance/Benchmarks.RepoDB.cs b/benchmarks/Dapper.Tests.Performance/Benchmarks.RepoDB.cs index 10694ea79..dd762afcf 100644 --- a/benchmarks/Dapper.Tests.Performance/Benchmarks.RepoDB.cs +++ b/benchmarks/Dapper.Tests.Performance/Benchmarks.RepoDB.cs @@ -20,11 +20,11 @@ public void Setup() // We need this since benchmarks using System.Data.SqlClient var dbSetting = new SqlServerDbSetting(); DbSettingMapper - .Add(dbSetting, true); + .Add(dbSetting, true); DbHelperMapper - .Add(new SqlServerDbHelper(), true); + .Add(new SqlServerDbHelper(), true); StatementBuilderMapper - .Add(new SqlServerStatementBuilder(dbSetting), true); + .Add(new SqlServerStatementBuilder(dbSetting), true); ClassMapper.Add("Posts"); } @@ -54,7 +54,7 @@ public Post QueryDynamic() public Post QueryField() { Step(); - return _connection.Query(new QueryField[] { new(nameof(Post.Id), i) }).First(); + return _connection.Query([new(nameof(Post.Id), i)]).First(); } [Benchmark(Description = "ExecuteQuery")] diff --git a/benchmarks/Dapper.Tests.Performance/Benchmarks.cs b/benchmarks/Dapper.Tests.Performance/Benchmarks.cs index aa5effb53..8a92b5e23 100644 --- a/benchmarks/Dapper.Tests.Performance/Benchmarks.cs +++ b/benchmarks/Dapper.Tests.Performance/Benchmarks.cs @@ -1,7 +1,7 @@ using BenchmarkDotNet.Attributes; using System; using System.Configuration; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; namespace Dapper.Tests.Performance { diff --git a/benchmarks/Dapper.Tests.Performance/LegacyTests.cs b/benchmarks/Dapper.Tests.Performance/LegacyTests.cs index dd9588b43..9bf4cdb46 100644 --- a/benchmarks/Dapper.Tests.Performance/LegacyTests.cs +++ b/benchmarks/Dapper.Tests.Performance/LegacyTests.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Data; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Diagnostics; using System.Linq; diff --git a/benchmarks/Dapper.Tests.Performance/Program.cs b/benchmarks/Dapper.Tests.Performance/Program.cs index 1e102cf87..4ffe7de9a 100644 --- a/benchmarks/Dapper.Tests.Performance/Program.cs +++ b/benchmarks/Dapper.Tests.Performance/Program.cs @@ -1,6 +1,6 @@ using BenchmarkDotNet.Running; using System; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using static System.Console; diff --git a/benchmarks/Dapper.Tests.Performance/SqlDataReaderHelper.cs b/benchmarks/Dapper.Tests.Performance/SqlDataReaderHelper.cs index d6d286e96..f7c215cda 100644 --- a/benchmarks/Dapper.Tests.Performance/SqlDataReaderHelper.cs +++ b/benchmarks/Dapper.Tests.Performance/SqlDataReaderHelper.cs @@ -1,5 +1,5 @@ using System; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Runtime.CompilerServices; namespace Dapper.Tests.Performance From 194089ea16b37fa4f81ac2a0ff92541dc009820e Mon Sep 17 00:00:00 2001 From: Marc Gravell Date: Sat, 25 Jan 2025 18:22:08 +0000 Subject: [PATCH 4/5] CI fix: test concurrency --- tests/Dapper.Tests/ParameterTests.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Dapper.Tests/ParameterTests.cs b/tests/Dapper.Tests/ParameterTests.cs index a5e3c4420..650624c20 100644 --- a/tests/Dapper.Tests/ParameterTests.cs +++ b/tests/Dapper.Tests/ParameterTests.cs @@ -17,6 +17,8 @@ using Microsoft.SqlServer.Types; #endif +[assembly: CollectionBehavior(DisableTestParallelization = true)] + namespace Dapper.Tests { [Collection(NonParallelDefinition.Name)] // because it creates SQL types that compete between the two providers From f6aa427d445c6cd3d52f17e1b2ed68daf759f16e Mon Sep 17 00:00:00 2001 From: Marc Gravell Date: Thu, 6 Feb 2025 12:10:13 +0000 Subject: [PATCH 5/5] rev snowflake --- Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index e85a64ccf..d72d03090 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -35,7 +35,7 @@ - +