From 7393c62659eac5adef832393072a1af6f751e55e Mon Sep 17 00:00:00 2001 From: MaceWindu Date: Sat, 12 Nov 2022 18:19:40 +0100 Subject: [PATCH] fix interceptors build against efcore7 --- .../Internal/LinqToDBOptionsExtension.cs | 7 +++---- .../LinqToDBContextOptionsBuilder.cs | 4 ++-- .../Interceptors/TestEfCoreAndLinq2DbComboInterceptor.cs | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Source/LinqToDB.EntityFrameworkCore/Internal/LinqToDBOptionsExtension.cs b/Source/LinqToDB.EntityFrameworkCore/Internal/LinqToDBOptionsExtension.cs index 5d834cb..2a305b4 100644 --- a/Source/LinqToDB.EntityFrameworkCore/Internal/LinqToDBOptionsExtension.cs +++ b/Source/LinqToDB.EntityFrameworkCore/Internal/LinqToDBOptionsExtension.cs @@ -100,13 +100,12 @@ public override string LogFragment } } - public override long GetServiceProviderHashCode() - { - return 0; - } + public override int GetServiceProviderHashCode() => 0; public override void PopulateDebugInfo(IDictionary debugInfo) => debugInfo["Linq2Db"] = "1"; + + public override bool ShouldUseSameServiceProvider(DbContextOptionsExtensionInfo other) => true; } } } diff --git a/Source/LinqToDB.EntityFrameworkCore/LinqToDBContextOptionsBuilder.cs b/Source/LinqToDB.EntityFrameworkCore/LinqToDBContextOptionsBuilder.cs index 07a22ef..9c129a2 100644 --- a/Source/LinqToDB.EntityFrameworkCore/LinqToDBContextOptionsBuilder.cs +++ b/Source/LinqToDB.EntityFrameworkCore/LinqToDBContextOptionsBuilder.cs @@ -10,7 +10,7 @@ namespace LinqToDB.EntityFrameworkCore /// public class LinqToDBContextOptionsBuilder { - private readonly LinqToDBOptionsExtension _extension; + private readonly LinqToDBOptionsExtension? _extension; /// /// Db context options @@ -34,7 +34,7 @@ public LinqToDBContextOptionsBuilder(DbContextOptionsBuilder optionsBuilder) /// public LinqToDBContextOptionsBuilder AddInterceptor(IInterceptor interceptor) { - _extension.Interceptors.Add(interceptor); + _extension?.Interceptors.Add(interceptor); return this; } } diff --git a/Tests/LinqToDB.EntityFrameworkCore.BaseTests/Interceptors/TestEfCoreAndLinq2DbComboInterceptor.cs b/Tests/LinqToDB.EntityFrameworkCore.BaseTests/Interceptors/TestEfCoreAndLinq2DbComboInterceptor.cs index 832b2e9..1bf7de1 100644 --- a/Tests/LinqToDB.EntityFrameworkCore.BaseTests/Interceptors/TestEfCoreAndLinq2DbComboInterceptor.cs +++ b/Tests/LinqToDB.EntityFrameworkCore.BaseTests/Interceptors/TestEfCoreAndLinq2DbComboInterceptor.cs @@ -147,13 +147,13 @@ public ValueTask> ReaderExecutingAsync(DbComman return ValueTask.FromResult(result); } - public object ScalarExecuted(DbCommand command, CommandExecutedEventData eventData, object result) + public object? ScalarExecuted(DbCommand command, CommandExecutedEventData eventData, object? result) { HasInterceptorBeenInvoked = true; return result; } - public ValueTask ScalarExecutedAsync(DbCommand command, CommandExecutedEventData eventData, object result, CancellationToken cancellationToken = default) + public ValueTask ScalarExecutedAsync(DbCommand command, CommandExecutedEventData eventData, object? result, CancellationToken cancellationToken = default) { HasInterceptorBeenInvoked = true; return ValueTask.FromResult(result);