Added support for EF Core 6

This commit is contained in:
Koen Bekkenutte
2021-09-17 02:22:40 +08:00
parent ef60fff059
commit 35fc7a2c78
14 changed files with 128 additions and 42 deletions
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>$(TargetFrameworkVersion)</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="$(EFCoreVersion)" />
</ItemGroup>
<ItemGroup>
@@ -1,5 +1,6 @@
using EntityFrameworkCore.Projectables.Infrastructure;
using EntityFrameworkCore.Projectables.Infrastructure.Internal;
using ZEntityFrameworkCore.Projectables.Infrastructure.Internal;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using System;
@@ -1,4 +1,6 @@
using Microsoft.EntityFrameworkCore.Infrastructure;
using EntityFrameworkCore.Projectables.Infrastructure;
using EntityFrameworkCore.Projectables.Infrastructure.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.Internal;
using Microsoft.Extensions.DependencyInjection;
@@ -10,7 +12,11 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFrameworkCore.Projectables.Infrastructure.Internal
// The Z in the namespace is not a typo
// We need to make sure that this extension is registered last.
// see: https://github.com/dotnet/efcore/issues/26071
namespace ZEntityFrameworkCore.Projectables.Infrastructure.Internal
{
public class ProjectionOptionsExtension : IDbContextOptionsExtension
{
@@ -96,29 +102,17 @@ namespace EntityFrameworkCore.Projectables.Infrastructure.Internal
sealed class ExtensionInfo : DbContextOptionsExtensionInfo
{
private int? _serviceProviderHash;
public ExtensionInfo(IDbContextOptionsExtension extension) : base(extension)
{
}
private new ProjectionOptionsExtension Extension
=> (ProjectionOptionsExtension)base.Extension;
public override bool IsDatabaseProvider => false;
public override string LogFragment => string.Empty;
public override long GetServiceProviderHashCode()
{
if (_serviceProviderHash == null)
{
var hashCode = nameof(ProjectionOptionsExtension).GetHashCode();
var extension = (ProjectionOptionsExtension)Extension;
hashCode ^= extension._compatibilityMode.GetHashCode();
_serviceProviderHash = hashCode;
}
return _serviceProviderHash.Value;
}
public override void PopulateDebugInfo(IDictionary<string, string> debugInfo)
{
@@ -127,8 +121,36 @@ namespace EntityFrameworkCore.Projectables.Infrastructure.Internal
throw new ArgumentNullException(nameof(debugInfo));
}
debugInfo["Projectables:CompatibilityMode"] = ((ProjectionOptionsExtension)Extension)._compatibilityMode.ToString();
debugInfo["Projectables:CompatibilityMode"] = Extension._compatibilityMode.ToString();
}
#if EFPROJECTABLES1
public override long GetServiceProviderHashCode()
{
var hashCode = nameof(ProjectionOptionsExtension).GetHashCode();
var extension = (ProjectionOptionsExtension)Extension;
hashCode ^= extension._compatibilityMode.GetHashCode();
return hashCode;
}
#endif
#if EFPROJECTABLES2
public override int GetServiceProviderHashCode()
{
var hashCode = new HashCode();
hashCode.Add(Extension._compatibilityMode);
return hashCode.ToHashCode();
}
public override bool ShouldUseSameServiceProvider(DbContextOptionsExtensionInfo other)
=> other is ExtensionInfo otherInfo && Extension._compatibilityMode == otherInfo.Extension._compatibilityMode;
#endif
}
}
}
@@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EntityFrameworkCore.Projectables.Infrastructure.Internal;
using ZEntityFrameworkCore.Projectables.Infrastructure.Internal;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;