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

View File

@@ -7,6 +7,7 @@
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<NoWarn>CS1591</NoWarn>
<Configurations>Debug;Release;DebugV1</Configurations>
</PropertyGroup>
<PropertyGroup>
@@ -19,4 +20,30 @@
<Description>Project over properties and functions in your linq queries</Description>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'DebugV1' Or '$(Configuration)' == 'ReleaseV1' ">
<EFProjectablesVersion>1</EFProjectablesVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(EFProjectablesVersion)' == '' ">
<EFProjectablesVersion>2</EFProjectablesVersion>
</PropertyGroup>
<PropertyGroup Condition=" $(EFProjectablesVersion) == 1 ">
<DefineConstants>EFPROJECTABLES1</DefineConstants>
<TargetFrameworkVersion>netstandard2.0</TargetFrameworkVersion>
<MicrosoftExtensionsVersion>3.1.0</MicrosoftExtensionsVersion>
<EFCoreVersion>3.1.0</EFCoreVersion>
<!-- We're testing against EF Core 5 as its compatible with 3.1.0 and contains additional features -->
<TestEFCoreVersion>5.0</TestEFCoreVersion>
</PropertyGroup>
<PropertyGroup Condition=" $(EFProjectablesVersion) == 2 ">
<DefineConstants>EFPROJECTABLES2</DefineConstants>
<TargetFrameworkVersion>net6.0</TargetFrameworkVersion>
<MicrosoftExtensionsVersion>6.0.0-rc.1.21451.13</MicrosoftExtensionsVersion>
<EFCoreVersion>6.0.0-rc.1.21452.10</EFCoreVersion>
<TestEFCoreVersion>$(EFCoreVersion)</TestEFCoreVersion>
</PropertyGroup>
</Project>

View File

@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31313.381
# Visual Studio Version 17
VisualStudioVersion = 17.0.31710.8
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{A43F1828-D9B6-40F7-82B6-CA0070843E2F}"
EndProject
@@ -33,50 +33,88 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReadmeSample", "samples\Rea
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmarks", "benchmarks", "{D1DB50EE-D639-46B0-8966-D0AA5F569620}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFrameworkCore.Projectables.Benchmarks", "benchmarks\EntityFrameworkCore.Projectables.Benchmarks\EntityFrameworkCore.Projectables.Benchmarks.csproj", "{F2F01B61-5FB8-4F96-A6DE-824C9756B365}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EntityFrameworkCore.Projectables.Benchmarks", "benchmarks\EntityFrameworkCore.Projectables.Benchmarks\EntityFrameworkCore.Projectables.Benchmarks.csproj", "{F2F01B61-5FB8-4F96-A6DE-824C9756B365}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
DebugV1|Any CPU = DebugV1|Any CPU
Release|Any CPU = Release|Any CPU
ReleaseV1|Any CPU = ReleaseV1|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{698E3EEC-64F9-4F96-B700-D61D04FD0704}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{698E3EEC-64F9-4F96-B700-D61D04FD0704}.Debug|Any CPU.Build.0 = Debug|Any CPU
{698E3EEC-64F9-4F96-B700-D61D04FD0704}.DebugV1|Any CPU.ActiveCfg = DebugV1|Any CPU
{698E3EEC-64F9-4F96-B700-D61D04FD0704}.DebugV1|Any CPU.Build.0 = DebugV1|Any CPU
{698E3EEC-64F9-4F96-B700-D61D04FD0704}.Release|Any CPU.ActiveCfg = Release|Any CPU
{698E3EEC-64F9-4F96-B700-D61D04FD0704}.Release|Any CPU.Build.0 = Release|Any CPU
{698E3EEC-64F9-4F96-B700-D61D04FD0704}.ReleaseV1|Any CPU.ActiveCfg = Release|Any CPU
{698E3EEC-64F9-4F96-B700-D61D04FD0704}.ReleaseV1|Any CPU.Build.0 = Release|Any CPU
{20F85652-2923-4211-9262-C64BA8C9ED89}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{20F85652-2923-4211-9262-C64BA8C9ED89}.Debug|Any CPU.Build.0 = Debug|Any CPU
{20F85652-2923-4211-9262-C64BA8C9ED89}.DebugV1|Any CPU.ActiveCfg = DebugV1|Any CPU
{20F85652-2923-4211-9262-C64BA8C9ED89}.DebugV1|Any CPU.Build.0 = DebugV1|Any CPU
{20F85652-2923-4211-9262-C64BA8C9ED89}.Release|Any CPU.ActiveCfg = Release|Any CPU
{20F85652-2923-4211-9262-C64BA8C9ED89}.Release|Any CPU.Build.0 = Release|Any CPU
{20F85652-2923-4211-9262-C64BA8C9ED89}.ReleaseV1|Any CPU.ActiveCfg = Release|Any CPU
{20F85652-2923-4211-9262-C64BA8C9ED89}.ReleaseV1|Any CPU.Build.0 = Release|Any CPU
{EE4D6CC1-78DE-4279-A567-C3D360C479F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EE4D6CC1-78DE-4279-A567-C3D360C479F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EE4D6CC1-78DE-4279-A567-C3D360C479F8}.DebugV1|Any CPU.ActiveCfg = DebugV1|Any CPU
{EE4D6CC1-78DE-4279-A567-C3D360C479F8}.DebugV1|Any CPU.Build.0 = DebugV1|Any CPU
{EE4D6CC1-78DE-4279-A567-C3D360C479F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EE4D6CC1-78DE-4279-A567-C3D360C479F8}.Release|Any CPU.Build.0 = Release|Any CPU
{EE4D6CC1-78DE-4279-A567-C3D360C479F8}.ReleaseV1|Any CPU.ActiveCfg = Release|Any CPU
{EE4D6CC1-78DE-4279-A567-C3D360C479F8}.ReleaseV1|Any CPU.Build.0 = Release|Any CPU
{1B4A8710-4182-494D-B1C5-6B7CDB9C9DB9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1B4A8710-4182-494D-B1C5-6B7CDB9C9DB9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1B4A8710-4182-494D-B1C5-6B7CDB9C9DB9}.DebugV1|Any CPU.ActiveCfg = DebugV1|Any CPU
{1B4A8710-4182-494D-B1C5-6B7CDB9C9DB9}.DebugV1|Any CPU.Build.0 = DebugV1|Any CPU
{1B4A8710-4182-494D-B1C5-6B7CDB9C9DB9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1B4A8710-4182-494D-B1C5-6B7CDB9C9DB9}.Release|Any CPU.Build.0 = Release|Any CPU
{1B4A8710-4182-494D-B1C5-6B7CDB9C9DB9}.ReleaseV1|Any CPU.ActiveCfg = Release|Any CPU
{1B4A8710-4182-494D-B1C5-6B7CDB9C9DB9}.ReleaseV1|Any CPU.Build.0 = Release|Any CPU
{C8038180-36F8-4077-922B-91F428EAC7D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C8038180-36F8-4077-922B-91F428EAC7D9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C8038180-36F8-4077-922B-91F428EAC7D9}.DebugV1|Any CPU.ActiveCfg = DebugV1|Any CPU
{C8038180-36F8-4077-922B-91F428EAC7D9}.DebugV1|Any CPU.Build.0 = DebugV1|Any CPU
{C8038180-36F8-4077-922B-91F428EAC7D9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C8038180-36F8-4077-922B-91F428EAC7D9}.Release|Any CPU.Build.0 = Release|Any CPU
{C8038180-36F8-4077-922B-91F428EAC7D9}.ReleaseV1|Any CPU.ActiveCfg = Release|Any CPU
{C8038180-36F8-4077-922B-91F428EAC7D9}.ReleaseV1|Any CPU.Build.0 = Release|Any CPU
{2F0DD7D7-867F-4478-9E22-45C114B61C46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2F0DD7D7-867F-4478-9E22-45C114B61C46}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2F0DD7D7-867F-4478-9E22-45C114B61C46}.DebugV1|Any CPU.ActiveCfg = DebugV1|Any CPU
{2F0DD7D7-867F-4478-9E22-45C114B61C46}.DebugV1|Any CPU.Build.0 = DebugV1|Any CPU
{2F0DD7D7-867F-4478-9E22-45C114B61C46}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2F0DD7D7-867F-4478-9E22-45C114B61C46}.Release|Any CPU.Build.0 = Release|Any CPU
{2F0DD7D7-867F-4478-9E22-45C114B61C46}.ReleaseV1|Any CPU.ActiveCfg = Release|Any CPU
{2F0DD7D7-867F-4478-9E22-45C114B61C46}.ReleaseV1|Any CPU.Build.0 = Release|Any CPU
{A36F5471-0C16-4453-811B-818326931313}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A36F5471-0C16-4453-811B-818326931313}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A36F5471-0C16-4453-811B-818326931313}.DebugV1|Any CPU.ActiveCfg = DebugV1|Any CPU
{A36F5471-0C16-4453-811B-818326931313}.DebugV1|Any CPU.Build.0 = DebugV1|Any CPU
{A36F5471-0C16-4453-811B-818326931313}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A36F5471-0C16-4453-811B-818326931313}.Release|Any CPU.Build.0 = Release|Any CPU
{A36F5471-0C16-4453-811B-818326931313}.ReleaseV1|Any CPU.ActiveCfg = Release|Any CPU
{A36F5471-0C16-4453-811B-818326931313}.ReleaseV1|Any CPU.Build.0 = Release|Any CPU
{6F63E04C-9267-4211-8AC7-290C60331D60}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6F63E04C-9267-4211-8AC7-290C60331D60}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6F63E04C-9267-4211-8AC7-290C60331D60}.DebugV1|Any CPU.ActiveCfg = DebugV1|Any CPU
{6F63E04C-9267-4211-8AC7-290C60331D60}.DebugV1|Any CPU.Build.0 = DebugV1|Any CPU
{6F63E04C-9267-4211-8AC7-290C60331D60}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6F63E04C-9267-4211-8AC7-290C60331D60}.Release|Any CPU.Build.0 = Release|Any CPU
{6F63E04C-9267-4211-8AC7-290C60331D60}.ReleaseV1|Any CPU.ActiveCfg = Release|Any CPU
{6F63E04C-9267-4211-8AC7-290C60331D60}.ReleaseV1|Any CPU.Build.0 = Release|Any CPU
{F2F01B61-5FB8-4F96-A6DE-824C9756B365}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F2F01B61-5FB8-4F96-A6DE-824C9756B365}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F2F01B61-5FB8-4F96-A6DE-824C9756B365}.DebugV1|Any CPU.ActiveCfg = DebugV1|Any CPU
{F2F01B61-5FB8-4F96-A6DE-824C9756B365}.DebugV1|Any CPU.Build.0 = DebugV1|Any CPU
{F2F01B61-5FB8-4F96-A6DE-824C9756B365}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F2F01B61-5FB8-4F96-A6DE-824C9756B365}.Release|Any CPU.Build.0 = Release|Any CPU
{F2F01B61-5FB8-4F96-A6DE-824C9756B365}.ReleaseV1|Any CPU.ActiveCfg = Release|Any CPU
{F2F01B61-5FB8-4F96-A6DE-824C9756B365}.ReleaseV1|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@@ -2,13 +2,13 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="$(TestEFCoreVersion)" />
</ItemGroup>
<ItemGroup>

View File

@@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<Nullable>disable</Nullable>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)Generated</CompilerGeneratedFilesOutputPath>
@@ -10,9 +10,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.6" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="$(EFCoreVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="$(MicrosoftExtensionsVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="$(MicrosoftExtensionsVersion)" />
</ItemGroup>
<ItemGroup>

View File

@@ -43,7 +43,6 @@ namespace ReadmeSample
Console.WriteLine($"Jons latest order had a grant total of {result.GrandTotal}");
Console.WriteLine($"The following query was used to fetch the results:");
Console.WriteLine(query.ToQueryString());
}
}
}

View File

@@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<Nullable>disable</Nullable>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)Generated</CompilerGeneratedFilesOutputPath>
@@ -10,9 +10,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.6" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="$(EFCoreVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="$(MicrosoftExtensionsVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="$(MicrosoftExtensionsVersion)" />
</ItemGroup>
<ItemGroup>

View File

@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>

View File

@@ -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>

View File

@@ -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;

View File

@@ -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
}
}
}

View File

@@ -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;

View File

@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)Generated</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="$(TestEFCoreVersion)" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="ScenarioTests.XUnit" Version="0.5.2" />
<PackageReference Include="Verify.Xunit" Version="11.5.0" />

View File

@@ -1,8 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

View File

@@ -1,8 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>