diff --git a/benchmarks/ShardingCoreBenchmark/EFCoreCrud.cs b/benchmarks/ShardingCoreBenchmark/EFCoreCrud.cs index f55444b3..1d1de46c 100644 --- a/benchmarks/ShardingCoreBenchmark/EFCoreCrud.cs +++ b/benchmarks/ShardingCoreBenchmark/EFCoreCrud.cs @@ -1,30 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BenchmarkDotNet.Attributes; -using BenchmarkDotNet.Jobs; -using EFCore.BulkExtensions; +using BenchmarkDotNet.Attributes; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using ShardingCore; using ShardingCore.Bootstrapers; -using ShardingCore.Core.VirtualDatabase.VirtualDataSources; using ShardingCore.Core.VirtualDatabase.VirtualTables; -using ShardingCore.Core.VirtualRoutes.DataSourceRoutes.RouteRuleEngine; -using ShardingCore.Core.VirtualRoutes.TableRoutes; -using ShardingCore.Core.VirtualRoutes.TableRoutes.RouteTails.Abstractions; -using ShardingCore.Core.VirtualRoutes.TableRoutes.RoutingRuleEngine; -using ShardingCore.Core.VirtualTables; -using ShardingCore.Exceptions; using ShardingCore.Extensions; -using ShardingCore.Sharding; -using ShardingCore.Sharding.Abstractions; -using ShardingCore.Sharding.ShardingDbContextExecutors; using ShardingCore6x.NoShardingDbContexts; using ShardingCore6x.ShardingDbContexts; +using System.Diagnostics; namespace ShardingCore6x diff --git a/nuget-publish.bat b/nuget-publish.bat index e08796fa..4504a28a 100644 --- a/nuget-publish.bat +++ b/nuget-publish.bat @@ -1,9 +1,9 @@ :start ::定义版本 -set EFCORE2=2.4.0.01-preview2 -set EFCORE3=3.4.0.01-preview2 -set EFCORE5=5.4.0.01-preview2 -set EFCORE6=6.4.0.01-preview2 +set EFCORE2=2.4.0.01-preview3 +set EFCORE3=3.4.0.01-preview3 +set EFCORE5=5.4.0.01-preview3 +set EFCORE6=6.4.0.01-preview3 ::删除所有bin与obj下的文件 @echo off diff --git a/samples/Sample.MultiConfig/Controllers/TestController.cs b/samples/Sample.MultiConfig/Controllers/TestController.cs index cec72f90..9dff1165 100644 --- a/samples/Sample.MultiConfig/Controllers/TestController.cs +++ b/samples/Sample.MultiConfig/Controllers/TestController.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Sample.MultiConfig.Domain.Entities; +using ShardingCore.Core.VirtualDatabase.VirtualTables; namespace Sample.MultiConfig.Controllers { @@ -9,10 +10,12 @@ namespace Sample.MultiConfig.Controllers public class TestController:ControllerBase { private readonly MultiConfigDbContext _multiConfigDbContext; + private readonly IVirtualTableManager _virtualTableManager; - public TestController(MultiConfigDbContext multiConfigDbContext) + public TestController(MultiConfigDbContext multiConfigDbContext,IVirtualTableManager virtualTableManager) { _multiConfigDbContext = multiConfigDbContext; + _virtualTableManager = virtualTableManager; } public async Task Add() { diff --git a/src/ShardingCore/Bootstrapers/ShardingDbContextBootstrapper.cs b/src/ShardingCore/Bootstrapers/ShardingDbContextBootstrapper.cs index 8ef4116f..596426ac 100644 --- a/src/ShardingCore/Bootstrapers/ShardingDbContextBootstrapper.cs +++ b/src/ShardingCore/Bootstrapers/ShardingDbContextBootstrapper.cs @@ -99,9 +99,9 @@ namespace ShardingCore.Bootstrapers using (_virtualDataSourceManager.CreateScope(configId)) { //var dataSourceName = _virtualDataSource.DefaultDataSourceName; + using var context = (DbContext)serviceScope.ServiceProvider.GetService(_shardingDbContextType); - foreach (var entity in context.Model.GetEntityTypes()) { var entityType = entity.ClrType; diff --git a/src/ShardingCore/Core/ShardingConfigurations/ConfigBuilders/ShardingConfigBuilder.cs b/src/ShardingCore/Core/ShardingConfigurations/ConfigBuilders/ShardingConfigBuilder.cs index acfedc6b..52b6f66e 100644 --- a/src/ShardingCore/Core/ShardingConfigurations/ConfigBuilders/ShardingConfigBuilder.cs +++ b/src/ShardingCore/Core/ShardingConfigurations/ConfigBuilders/ShardingConfigBuilder.cs @@ -43,9 +43,9 @@ namespace ShardingCore.Core.ShardingConfigurations.ConfigBuilders throw new ArgumentNullException( $"{nameof(shardingGlobalConfigOptions.DefaultConnectionString)} plz call {nameof(ShardingConfigOptions.AddDefaultDataSource)}"); - if (shardingGlobalConfigOptions.ConnectionStringConfigure is null) + if (shardingGlobalConfigOptions.ConnectionStringConfigure is null&& ShardingCoreConfigBuilder.ShardingEntityConfigOptions.ConnectionStringConfigure is null) throw new ArgumentNullException($"plz call {nameof(shardingGlobalConfigOptions.UseShardingQuery)}"); - if (shardingGlobalConfigOptions.ConnectionConfigure is null) + if (shardingGlobalConfigOptions.ConnectionConfigure is null && ShardingCoreConfigBuilder.ShardingEntityConfigOptions.ConnectionConfigure is null) throw new ArgumentNullException( $"plz call {nameof(shardingGlobalConfigOptions.UseShardingTransaction)}"); diff --git a/src/ShardingCore/Core/VirtualDatabase/VirtualDataSources/VirtualDataSourceManager.cs b/src/ShardingCore/Core/VirtualDatabase/VirtualDataSources/VirtualDataSourceManager.cs index 92bff0ac..009720f2 100644 --- a/src/ShardingCore/Core/VirtualDatabase/VirtualDataSources/VirtualDataSourceManager.cs +++ b/src/ShardingCore/Core/VirtualDatabase/VirtualDataSources/VirtualDataSourceManager.cs @@ -140,8 +140,11 @@ namespace ShardingCore.Core.VirtualDatabase.VirtualDataSources if (IsMultiShardingConfiguration && ShardingConfigurationStrategy == ShardingConfigurationStrategyEnum.ReturnHighPriority) { var maxShardingConfiguration = _virtualDataSources.Values.OrderByDescending(o => o.Priority).FirstOrDefault(); - _defaultVirtualDataSource = maxShardingConfiguration; - _defaultConfigId = maxShardingConfiguration.ConfigId; + if (maxShardingConfiguration.ConfigId != _defaultConfigId) + { + _defaultConfigId = maxShardingConfiguration.ConfigId; + _defaultVirtualDataSource = maxShardingConfiguration; + } } }