[#22] 支持ef-core6.0,发布x.3.1.31
This commit is contained in:
parent
3769fe0d6c
commit
7be87935fa
|
@ -1,9 +1,9 @@
|
|||
:start
|
||||
::定义版本
|
||||
set EFCORE2=2.3.1.30
|
||||
set EFCORE3=3.3.1.30
|
||||
set EFCORE5=5.3.1.30
|
||||
set EFCORE6=5.3.1.30
|
||||
set EFCORE2=2.3.1.31
|
||||
set EFCORE3=3.3.1.31
|
||||
set EFCORE5=5.3.1.31
|
||||
set EFCORE6=6.3.1.31
|
||||
|
||||
::删除所有bin与obj下的文件
|
||||
@echo off
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="EFCore.BulkExtensions" Version="5.3.9" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.10" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" />
|
||||
<PackageReference Include="EFCore.BulkExtensions" Version="6.0.0-rc.2" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\ShardingCore\ShardingCore.csproj" />
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.10">
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<LangVersion>9.0</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="EFCore.BulkExtensions" Version="5.4.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.10" />
|
||||
<PackageReference Include="EFCore.BulkExtensions" Version="6.0.0-rc.2" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -82,7 +82,7 @@ namespace Sample.SqlServer
|
|||
app.UseRouting();
|
||||
|
||||
app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
|
||||
//app.DbSeed();
|
||||
app.DbSeed();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.11" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.11" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\ShardingCore\ShardingCore.csproj" />
|
||||
<ProjectReference Include="..\..\src5x\ShardingCore.5x\ShardingCore.5x.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -1,15 +1,12 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ChronusJob" Version="1.0.5" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.11" NoWarn="NU1605" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="5.0.1" NoWarn="NU1605" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.9" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -12,7 +12,6 @@ using Microsoft.Extensions.Configuration;
|
|||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Samples.AutoByDate.SqlServer.DbContexts;
|
||||
using Samples.AutoByDate.SqlServer.Shardings;
|
||||
using ShardingCore;
|
||||
|
@ -32,7 +31,6 @@ namespace Samples.AutoByDate.SqlServer
|
|||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddControllers();
|
||||
services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo {Title = "Samples.AutoByDate.SqlServer", Version = "v1"}); });
|
||||
|
||||
services.AddShardingDbContext<DefaultShardingDbContext>(
|
||||
(conn, o) => o.UseSqlServer(conn)
|
||||
|
@ -59,8 +57,6 @@ namespace Samples.AutoByDate.SqlServer
|
|||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Samples.AutoByDate.SqlServer v1"));
|
||||
}
|
||||
|
||||
app.UseShardingCore();
|
||||
|
|
|
@ -79,9 +79,9 @@ namespace ShardingCore.EFCores
|
|||
var tableName = entityMetadata.VirtualTableName;
|
||||
if (string.IsNullOrWhiteSpace(tableName))
|
||||
throw new ArgumentNullException($"{shardingEntity}: not found original table name。");
|
||||
//#if DEBUG
|
||||
// Console.WriteLine($"mapping table :[tableName]-->[{tableName}{tableSeparator}{tail}]");
|
||||
//#endif
|
||||
#if DEBUG
|
||||
Console.WriteLine($"mapping table :[tableName]-->[{tableName}{tableSeparator}{tail}]");
|
||||
#endif
|
||||
entity.ToTable($"{tableName}{tableSeparator}{tail}");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace ShardingCore.Extensions
|
|||
{
|
||||
#if EFCORE6
|
||||
|
||||
var contextModel = dbContext.Model as RuntimeModel;
|
||||
var contextModel = dbContext.GetService<IDesignTimeModel>().Model; ;
|
||||
#endif
|
||||
#if EFCORE2 || EFCORE3 || EFCORE5
|
||||
|
||||
|
@ -45,7 +45,7 @@ namespace ShardingCore.Extensions
|
|||
contextModelRelationalModel.Tables.Remove(valueTuples[i]);
|
||||
}
|
||||
#endif
|
||||
#if EFCORE5
|
||||
#if EFCORE5
|
||||
var contextModelRelationalModel = contextModel.RelationalModel as RelationalModel;
|
||||
var valueTuples =
|
||||
contextModelRelationalModel.Tables.Where(o => o.Value.EntityTypeMappings.Any(m => entityMetadataManager.IsShardingTable(m.EntityType.ClrType))).Select(o => o.Key).ToList();
|
||||
|
@ -54,7 +54,7 @@ namespace ShardingCore.Extensions
|
|||
contextModelRelationalModel.Tables.Remove(valueTuples[i]);
|
||||
}
|
||||
#endif
|
||||
#if EFCORE2 ||EFCORE3
|
||||
#if EFCORE2 || EFCORE3
|
||||
var entityTypes =
|
||||
contextModel.GetFieldValue("_entityTypes") as SortedDictionary<string, EntityType>;
|
||||
var list = entityTypes.Where(o=>entityMetadataManager.IsShardingTable(o.Value.ClrType)).Select(o=>o.Key).ToList();
|
||||
|
@ -75,7 +75,7 @@ namespace ShardingCore.Extensions
|
|||
{
|
||||
#if EFCORE6
|
||||
|
||||
var contextModel = dbContext.Model as RuntimeModel;
|
||||
var contextModel = dbContext.GetService<IDesignTimeModel>().Model; ;
|
||||
#endif
|
||||
#if EFCORE2 ||EFCORE3 ||EFCORE5
|
||||
|
||||
|
@ -126,9 +126,8 @@ namespace ShardingCore.Extensions
|
|||
/// <param name="dbContext"></param>
|
||||
public static void RemoveModelCache(this DbContext dbContext)
|
||||
{
|
||||
var serviceScope = typeof(DbContext).GetTypeFieldValue(dbContext, "_serviceScope") as IServiceScope;
|
||||
#if EFCORE6
|
||||
var dependencies = serviceScope.ServiceProvider.GetService<ModelCreationDependencies>();
|
||||
var dependencies = dbContext.GetService<ModelCreationDependencies>();
|
||||
var dependenciesModelSource = dependencies.ModelSource as ModelSource;
|
||||
|
||||
var modelSourceDependencies =
|
||||
|
@ -138,7 +137,7 @@ namespace ShardingCore.Extensions
|
|||
memoryCache.Remove(key1);
|
||||
#endif
|
||||
#if EFCORE5
|
||||
var dependencies = serviceScope.ServiceProvider.GetService<IModelCreationDependencies>();
|
||||
var dependencies = dbContext.GetService<IModelCreationDependencies>();
|
||||
var dependenciesModelSource = dependencies.ModelSource as ModelSource;
|
||||
|
||||
var modelSourceDependencies =
|
||||
|
@ -149,7 +148,7 @@ namespace ShardingCore.Extensions
|
|||
#endif
|
||||
#if EFCORE3
|
||||
|
||||
var modelSource = serviceScope.ServiceProvider.GetService<IModelSource>();
|
||||
var modelSource = dbContext.GetService<IModelSource>();
|
||||
var modelSourceImpl = modelSource as ModelSource;
|
||||
|
||||
var modelSourceDependencies =
|
||||
|
@ -161,7 +160,7 @@ namespace ShardingCore.Extensions
|
|||
|
||||
#if EFCORE2
|
||||
|
||||
var modelSource = serviceScope.ServiceProvider.GetService<IModelSource>();
|
||||
var modelSource = dbContext.GetService<IModelSource>();
|
||||
var modelSourceImpl = modelSource as RelationalModelSource;
|
||||
|
||||
var modelSourceDependencies =
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"SqlServer": {
|
||||
"ConnectionString": "Data Source=localhost;Initial Catalog=ShardingCoreDB;Integrated Security=True;"
|
||||
"ConnectionString": "Data Source=localhost;Initial Catalog=ShardingCoreDBxxxx;Integrated Security=True;"
|
||||
},
|
||||
"MySql": {
|
||||
"ConnectionString": "server=127.0.0.1;port=3306;user=root;password=root;database=ShardingCoreDB;sslMode=None;"
|
||||
|
|
|
@ -46,8 +46,8 @@ namespace ShardingCore.Test6x
|
|||
o.UseSqlServer(conn).UseLoggerFactory(efLogger))
|
||||
.Begin(o =>
|
||||
{
|
||||
//o.CreateShardingTableOnStart = true;
|
||||
//o.EnsureCreatedWithOutShardingTable = true;
|
||||
o.CreateShardingTableOnStart = true;
|
||||
o.EnsureCreatedWithOutShardingTable = true;
|
||||
o.AutoTrackEntity = true;
|
||||
})
|
||||
.AddShardingTransaction((connection, builder) =>
|
||||
|
|
Loading…
Reference in New Issue