From 70fb82b4afccd3732d89be5bf9cd0ab019a08358 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Fri, 30 Aug 2024 19:30:05 +1000 Subject: [PATCH] drop sql classic --- pages/directory-and-name-resolution.md | 4 +-- src/Directory.Build.props | 1 - src/EfClassicLocalDb.Tests/Tests.cs | 6 ++-- src/EfClassicLocalDb/GlobalUsings.cs | 3 +- .../QuietConfig/ManifestTokenResolver.cs | 2 +- src/EfClassicLocalDb/ServiceScope.cs | 14 +++----- src/EfClassicLocalDb/SqlDatabase.cs | 8 ++--- src/EfClassicLocalDb/SqlDatabase_Service.cs | 4 +-- src/EfClassicLocalDb/SqlInstance.cs | 2 +- src/EfLocalDb.Tests/Tests.cs | 1 - src/EfLocalDb/EfLocalDb.csproj | 1 - src/EfLocalDb/ServiceScope.cs | 9 +---- src/EfLocalDb/SqlDatabase.cs | 22 ------------ src/EfLocalDb/SqlDatabase_Service.cs | 9 +---- src/LocalDb.Tests/Tests.cs | 5 +-- src/LocalDb/LocalDb.csproj | 1 - src/LocalDb/ServiceScope.cs | 19 +++------- src/LocalDb/SqlDatabase.cs | 35 ++----------------- src/LocalDb/SqlDatabase_Service.cs | 9 +---- src/LocalDb/SqlInstance.cs | 29 --------------- 20 files changed, 31 insertions(+), 153 deletions(-) diff --git a/pages/directory-and-name-resolution.md b/pages/directory-and-name-resolution.md index 37ee780e..9a1d7163 100644 --- a/pages/directory-and-name-resolution.md +++ b/pages/directory-and-name-resolution.md @@ -113,7 +113,7 @@ public Task Build( string? databaseSuffix = null, [CallerMemberName] string memberName = "") ``` -snippet source | anchor +snippet source | anchor With these parameters the database name is the derived as follows: @@ -150,7 +150,7 @@ If full control over the database name is required, there is an overload that ta /// public async Task Build(string dbName) ``` -snippet source | anchor +snippet source | anchor Which can be used as follows: diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 130433f6..dd0d06e8 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -20,7 +20,6 @@ - \ No newline at end of file diff --git a/src/EfClassicLocalDb.Tests/Tests.cs b/src/EfClassicLocalDb.Tests/Tests.cs index 00ec1bee..68b5893e 100644 --- a/src/EfClassicLocalDb.Tests/Tests.cs +++ b/src/EfClassicLocalDb.Tests/Tests.cs @@ -1,4 +1,6 @@ -[Collection("Sequential")] +using System.Data.SqlClient; + +[Collection("Sequential")] public class Tests { static SqlInstance instance; @@ -21,7 +23,7 @@ public async Task ServiceScope() { static void Add(List objects, IServiceProvider provider) { - objects.Add(provider.GetService()); + objects.Add(provider.GetService()); objects.Add(provider.GetService()); } diff --git a/src/EfClassicLocalDb/GlobalUsings.cs b/src/EfClassicLocalDb/GlobalUsings.cs index 4b7f6283..a2ecb56c 100644 --- a/src/EfClassicLocalDb/GlobalUsings.cs +++ b/src/EfClassicLocalDb/GlobalUsings.cs @@ -1,2 +1,3 @@ global using System.Data.Entity; -global using System.ComponentModel; \ No newline at end of file +global using System.ComponentModel; +global using System.Data.SqlClient; \ No newline at end of file diff --git a/src/EfClassicLocalDb/QuietConfig/ManifestTokenResolver.cs b/src/EfClassicLocalDb/QuietConfig/ManifestTokenResolver.cs index 9a005035..6393f7ef 100644 --- a/src/EfClassicLocalDb/QuietConfig/ManifestTokenResolver.cs +++ b/src/EfClassicLocalDb/QuietConfig/ManifestTokenResolver.cs @@ -7,7 +7,7 @@ class ManifestTokenResolver : public string ResolveManifestToken(DbConnection connection) { - if (connection is DataSqlConnection) + if (connection is SqlConnection) { return "2012"; } diff --git a/src/EfClassicLocalDb/ServiceScope.cs b/src/EfClassicLocalDb/ServiceScope.cs index 1e859030..ba99af60 100644 --- a/src/EfClassicLocalDb/ServiceScope.cs +++ b/src/EfClassicLocalDb/ServiceScope.cs @@ -1,16 +1,10 @@ #if(NET7_0_OR_GREATER) -class ServiceScope : +class ServiceScope(DbContext context, SqlConnection connection) : IServiceScope, IServiceProvider { - DbContext context; - DataSqlConnection connection; - - public ServiceScope(DbContext context, DataSqlConnection connection) - { - this.context = context; - this.connection = connection; - } + DbContext context = context; + SqlConnection connection = connection; public void Dispose() { @@ -22,7 +16,7 @@ public void Dispose() public object? GetService(Type type) { - if (type == typeof(DataSqlConnection)) + if (type == typeof(SqlConnection)) { return connection; } diff --git a/src/EfClassicLocalDb/SqlDatabase.cs b/src/EfClassicLocalDb/SqlDatabase.cs index fabd3b35..9fcc63a6 100644 --- a/src/EfClassicLocalDb/SqlDatabase.cs +++ b/src/EfClassicLocalDb/SqlDatabase.cs @@ -24,19 +24,19 @@ internal SqlDatabase( } public string Name { get; } - public DataSqlConnection Connection { get; } + public SqlConnection Connection { get; } public string ConnectionString { get; } - public async Task OpenNewConnection() + public async Task OpenNewConnection() { - var connection = new DataSqlConnection(ConnectionString); + var connection = new SqlConnection(ConnectionString); await connection.OpenAsync(); return connection; } public static implicit operator TDbContext(SqlDatabase instance) => instance.Context; - public static implicit operator DataSqlConnection(SqlDatabase instance) => instance.Connection; + public static implicit operator SqlConnection(SqlDatabase instance) => instance.Connection; public async Task Start() { diff --git a/src/EfClassicLocalDb/SqlDatabase_Service.cs b/src/EfClassicLocalDb/SqlDatabase_Service.cs index ccadf494..3d62054c 100644 --- a/src/EfClassicLocalDb/SqlDatabase_Service.cs +++ b/src/EfClassicLocalDb/SqlDatabase_Service.cs @@ -8,7 +8,7 @@ public partial class SqlDatabase : { public object? GetService(Type type) { - if (type == typeof(DataSqlConnection)) + if (type == typeof(SqlConnection)) { return Connection; } @@ -31,7 +31,7 @@ public partial class SqlDatabase : #if(NET7_0_OR_GREATER) public IServiceScope CreateScope() { - var connection = new DataSqlConnection(ConnectionString); + var connection = new SqlConnection(ConnectionString); connection.Open(); return new ServiceScope(NewDbContext(), connection); } diff --git a/src/EfClassicLocalDb/SqlInstance.cs b/src/EfClassicLocalDb/SqlInstance.cs index f448965a..192f7051 100644 --- a/src/EfClassicLocalDb/SqlInstance.cs +++ b/src/EfClassicLocalDb/SqlInstance.cs @@ -69,7 +69,7 @@ public SqlInstance( } Wrapper = new( - _ => new DataSqlConnection(_), + _ => new SqlConnection(_), storageValue.Name, storageValue.Directory, templateSize, diff --git a/src/EfLocalDb.Tests/Tests.cs b/src/EfLocalDb.Tests/Tests.cs index fd0834da..9dd2e5f0 100644 --- a/src/EfLocalDb.Tests/Tests.cs +++ b/src/EfLocalDb.Tests/Tests.cs @@ -23,7 +23,6 @@ public async Task ServiceScope() { static void Add(List objects, IServiceProvider provider) { - objects.Add(provider.GetService()); objects.Add(provider.GetService()); objects.Add(provider.GetService()); } diff --git a/src/EfLocalDb/EfLocalDb.csproj b/src/EfLocalDb/EfLocalDb.csproj index 7152c4f5..547fa81b 100644 --- a/src/EfLocalDb/EfLocalDb.csproj +++ b/src/EfLocalDb/EfLocalDb.csproj @@ -35,7 +35,6 @@ - diff --git a/src/EfLocalDb/ServiceScope.cs b/src/EfLocalDb/ServiceScope.cs index d7ea7e45..c9417f9d 100644 --- a/src/EfLocalDb/ServiceScope.cs +++ b/src/EfLocalDb/ServiceScope.cs @@ -1,4 +1,4 @@ -class ServiceScope(DbContext context, DataSqlConnection dataConnection, SqlConnection connection) : +class ServiceScope(DbContext context, SqlConnection connection) : IServiceScope, IServiceProvider, IAsyncDisposable @@ -6,14 +6,12 @@ class ServiceScope(DbContext context, DataSqlConnection dataConnection, SqlConne public void Dispose() { connection.Dispose(); - dataConnection.Dispose(); context.Dispose(); } public async ValueTask DisposeAsync() { await connection.DisposeAsync(); - await dataConnection.DisposeAsync(); await context.DisposeAsync(); } @@ -21,11 +19,6 @@ public async ValueTask DisposeAsync() public object? GetService(Type type) { - if (type == typeof(DataSqlConnection)) - { - return dataConnection; - } - if (type == typeof(SqlConnection)) { return connection; diff --git a/src/EfLocalDb/SqlDatabase.cs b/src/EfLocalDb/SqlDatabase.cs index 57441ea9..47af86fd 100644 --- a/src/EfLocalDb/SqlDatabase.cs +++ b/src/EfLocalDb/SqlDatabase.cs @@ -28,18 +28,10 @@ internal SqlDatabase( this.sqlOptionsBuilder = sqlOptionsBuilder; ConnectionString = connectionString; Connection = new(connectionString); - dataConnection = new(() => - { - var connection = new DataSqlConnection(connectionString); - connection.Open(); - return connection; - }); } public string Name { get; } public SqlConnection Connection { get; } - Lazy dataConnection; - public DataSqlConnection DataConnection => dataConnection.Value; public string ConnectionString { get; } public async Task OpenNewConnection() @@ -49,21 +41,12 @@ public async Task OpenNewConnection() return connection; } - public async Task OpenNewDataConnection() - { - var connection = new DataSqlConnection(ConnectionString); - await connection.OpenAsync(); - return connection; - } - public static implicit operator TDbContext(SqlDatabase instance) => instance.Context; public static implicit operator SqlConnection(SqlDatabase instance) => instance.Connection; public static implicit operator DbConnection(SqlDatabase instance) => instance.Connection; - public static implicit operator DataSqlConnection(SqlDatabase instance) => instance.DataConnection; - public async Task Start() { await Connection.OpenAsync(); @@ -115,11 +98,6 @@ public async ValueTask DisposeAsync() // ReSharper restore ConditionIsAlwaysTrueOrFalse await Connection.DisposeAsync(); - - if (dataConnection.IsValueCreated) - { - await dataConnection.Value.DisposeAsync(); - } } public async Task Delete() diff --git a/src/EfLocalDb/SqlDatabase_Service.cs b/src/EfLocalDb/SqlDatabase_Service.cs index 105c554c..3d62054c 100644 --- a/src/EfLocalDb/SqlDatabase_Service.cs +++ b/src/EfLocalDb/SqlDatabase_Service.cs @@ -13,11 +13,6 @@ public partial class SqlDatabase : return Connection; } - if (type == typeof(DataSqlConnection)) - { - return DataConnection; - } - if (type == typeof(TDbContext)) { return Context; @@ -38,9 +33,7 @@ public IServiceScope CreateScope() { var connection = new SqlConnection(ConnectionString); connection.Open(); - var dataConnection = new DataSqlConnection(ConnectionString); - dataConnection.Open(); - return new ServiceScope(NewDbContext(), dataConnection, connection); + return new ServiceScope(NewDbContext(), connection); } public AsyncServiceScope CreateAsyncScope() => diff --git a/src/LocalDb.Tests/Tests.cs b/src/LocalDb.Tests/Tests.cs index 4d97e7ee..b6e0c3a2 100644 --- a/src/LocalDb.Tests/Tests.cs +++ b/src/LocalDb.Tests/Tests.cs @@ -15,11 +15,8 @@ public async Task Simple() [Fact] public async Task ServiceScope() { - static void Add(List objects, IServiceProvider provider) - { - objects.Add(provider.GetService()); + static void Add(List objects, IServiceProvider provider) => objects.Add(provider.GetService()); - } var instance = new SqlInstance("ServiceScope", TestDbBuilder.CreateTable); diff --git a/src/LocalDb/LocalDb.csproj b/src/LocalDb/LocalDb.csproj index eee06311..5d48023d 100644 --- a/src/LocalDb/LocalDb.csproj +++ b/src/LocalDb/LocalDb.csproj @@ -10,7 +10,6 @@ - diff --git a/src/LocalDb/ServiceScope.cs b/src/LocalDb/ServiceScope.cs index 6ef2a03d..7236637c 100644 --- a/src/LocalDb/ServiceScope.cs +++ b/src/LocalDb/ServiceScope.cs @@ -1,4 +1,4 @@ -class ServiceScope(DataSqlConnection dataConnection, SqlConnection connection) : +class ServiceScope(SqlConnection connection) : #if(NET5_0_OR_GREATER) IAsyncDisposable, #endif @@ -7,29 +7,18 @@ class ServiceScope(DataSqlConnection dataConnection, SqlConnection connection) : #endif IServiceProvider { - public void Dispose() - { + public void Dispose() => connection.Dispose(); - dataConnection.Dispose(); - } #if(NET5_0_OR_GREATER) - public async ValueTask DisposeAsync() - { - await connection.DisposeAsync(); - await dataConnection.DisposeAsync(); - } + public ValueTask DisposeAsync() => + connection.DisposeAsync(); #endif public IServiceProvider ServiceProvider => this; public object? GetService(Type type) { - if (type == typeof(DataSqlConnection)) - { - return dataConnection; - } - if (type == typeof(SqlConnection)) { return connection; diff --git a/src/LocalDb/SqlDatabase.cs b/src/LocalDb/SqlDatabase.cs index 5386d99c..e5e2c24f 100644 --- a/src/LocalDb/SqlDatabase.cs +++ b/src/LocalDb/SqlDatabase.cs @@ -14,27 +14,17 @@ internal SqlDatabase(string connectionString, string name, Func delete) ConnectionString = connectionString; Name = name; Connection = new(connectionString); - dataConnection = new(() => - { - var connection = new DataSqlConnection(connectionString); - connection.Open(); - return connection; - }); } public string ConnectionString { get; } public string Name { get; } public SqlConnection Connection { get; } - Lazy dataConnection; - public DataSqlConnection DataConnection => dataConnection.Value; public static implicit operator SqlConnection(SqlDatabase instance) => instance.Connection; public static implicit operator DbConnection(SqlDatabase instance) => instance.Connection; - public static implicit operator DataSqlConnection(SqlDatabase instance) => instance.DataConnection; - public async Task OpenNewConnection() { var connection = new SqlConnection(ConnectionString); @@ -42,33 +32,14 @@ public async Task OpenNewConnection() return connection; } - public async Task OpenNewDataConnection() - { - var connection = new DataSqlConnection(ConnectionString); - await connection.OpenAsync(); - return connection; - } - public Task Start() => Connection.OpenAsync(); - public void Dispose() - { + public void Dispose() => Connection.Dispose(); - if (dataConnection.IsValueCreated) - { - dataConnection.Value.Dispose(); - } - } #if(!NET48) - public async ValueTask DisposeAsync() - { - await Connection.DisposeAsync(); - if (dataConnection.IsValueCreated) - { - await dataConnection.Value.DisposeAsync(); - } - } + public ValueTask DisposeAsync() => + Connection.DisposeAsync(); #endif // ReSharper disable once ReplaceAsyncWithTaskReturn diff --git a/src/LocalDb/SqlDatabase_Service.cs b/src/LocalDb/SqlDatabase_Service.cs index fe0f073d..691f7574 100644 --- a/src/LocalDb/SqlDatabase_Service.cs +++ b/src/LocalDb/SqlDatabase_Service.cs @@ -13,11 +13,6 @@ public partial class SqlDatabase : return Connection; } - if (type == typeof(DataSqlConnection)) - { - return DataConnection; - } - #if NET7_0_OR_GREATER if (type == typeof(IServiceScopeFactory)) { @@ -33,9 +28,7 @@ public IServiceScope CreateScope() { var connection = new SqlConnection(ConnectionString); connection.Open(); - var dataConnection = new DataSqlConnection(ConnectionString); - dataConnection.Open(); - return new ServiceScope(dataConnection, connection); + return new ServiceScope(connection); } public AsyncServiceScope CreateAsyncScope() => diff --git a/src/LocalDb/SqlInstance.cs b/src/LocalDb/SqlInstance.cs index 6f526f9b..db9121cf 100644 --- a/src/LocalDb/SqlInstance.cs +++ b/src/LocalDb/SqlInstance.cs @@ -33,35 +33,6 @@ public SqlInstance( Wrapper.Start(resultTimestamp, buildTemplate); } - public SqlInstance( - string name, - Func buildTemplate, - string? directory = null, - DateTime? timestamp = null, - ushort templateSize = 3, - ExistingTemplate? exitingTemplate = null, - Func? callback = null) : - this( - name, - connection => buildTemplate((DataSqlConnection) connection), - directory, - timestamp, - templateSize, - exitingTemplate, - connection => - { - if (callback == null) - { - return Task.CompletedTask; - } - - return callback.Invoke((DataSqlConnection) connection); - }, - _ => new DataSqlConnection(_)) - { - } - - public SqlInstance( string name, Func buildTemplate,