Support both net6 and net7

This commit is contained in:
2023-10-12 00:41:00 +02:00
parent 4fb6013aed
commit c15b970419
7 changed files with 23 additions and 12 deletions

View File

@@ -23,11 +23,15 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<TargetFrameworkVersion>net6.0</TargetFrameworkVersion> <TargetFrameworkVersion>net7.0;net6.0</TargetFrameworkVersion>
<MicrosoftExtensionsVersion>6.0.0</MicrosoftExtensionsVersion> <MicrosoftExtensionsVersion>6.0.0</MicrosoftExtensionsVersion>
<EFCoreVersion>6.0.0</EFCoreVersion> <EFCoreVersion>6.0.0</EFCoreVersion>
<TestEFCoreVersion>$(EFCoreVersion)</TestEFCoreVersion> <TestEFCoreVersion>$(EFCoreVersion)</TestEFCoreVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'net7.0'">
<EFCoreVersion>7.0.0</EFCoreVersion>
<TestEFCoreVersion>$(EFCoreVersion)</TestEFCoreVersion>
</PropertyGroup>
</Project> </Project>

View File

@@ -10,9 +10,9 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -159,6 +159,9 @@ namespace BasicSample
result = dbContext.Users.FirstOrDefault(x => x.TotalSpent > 1); result = dbContext.Users.FirstOrDefault(x => x.TotalSpent > 1);
Console.WriteLine($"Our first user {result.FullName} has spent {result.TotalSpent}"); Console.WriteLine($"Our first user {result.FullName} has spent {result.TotalSpent}");
var spent = dbContext.Users.Sum(x => x.TotalSpent);
Console.WriteLine($"Our users combined spent: {spent}");
} }
{ {

View File

@@ -10,9 +10,9 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFrameworks>net7.0;net6.0</TargetFrameworks>
<PackageReadmeFile>README.md</PackageReadmeFile> <PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup> </PropertyGroup>

View File

@@ -128,8 +128,8 @@ namespace EntityFrameworkCore.Projectables.Services
var self = _AddProjectableSelect(call.Arguments.First(), _entityType); var self = _AddProjectableSelect(call.Arguments.First(), _entityType);
return call.Update(null, call.Arguments.Skip(1).Prepend(self)); return call.Update(null, call.Arguments.Skip(1).Prepend(self));
} }
case QueryRootExpression root: case QueryRootExpression root when _entityType != null:
return _AddProjectableSelect(root, root.EntityType); return _AddProjectableSelect(root, _entityType);
default: default:
return ret; return ret;
} }
@@ -214,7 +214,11 @@ namespace EntityFrameworkCore.Projectables.Services
protected override Expression VisitExtension(Expression node) protected override Expression VisitExtension(Expression node)
{ {
#if NET7_0_OR_GREATER
if (node is EntityQueryRootExpression root)
#else
if (node is QueryRootExpression root) if (node is QueryRootExpression root)
#endif
{ {
_entityType = root.EntityType; _entityType = root.EntityType;
} }

View File

@@ -8,7 +8,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="$(TestEFCoreVersion)" /> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.12" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="ScenarioTests.XUnit" Version="1.0.0" /> <PackageReference Include="ScenarioTests.XUnit" Version="1.0.0" />
<PackageReference Include="Verify.Xunit" Version="11.5.0" /> <PackageReference Include="Verify.Xunit" Version="11.5.0" />