Revert "修复bootstrapper的启动获取dbcontext,data source db context 的创建dbcontextoptionbuilder"
This reverts commit b702f338e6
.
This commit is contained in:
parent
65ddd8aae3
commit
85afd7ce5e
|
@ -179,9 +179,7 @@ namespace Sample.SqlServer.Controllers
|
|||
{
|
||||
Stopwatch sp = new Stopwatch();
|
||||
sp.Start();
|
||||
var shardingPageResultAsync = await _defaultTableDbContext.Set<SysUserMod>()
|
||||
.UseConnectionMode(1).OrderBy(o => o.Age)
|
||||
.ToShardingPageAsync(p, s);
|
||||
var shardingPageResultAsync = await _defaultTableDbContext.Set<SysUserMod>().UseConnectionMode(1).OrderBy(o => o.Age).ToShardingPageAsync(p, s);
|
||||
sp.Stop();
|
||||
return Ok(new
|
||||
{
|
||||
|
|
|
@ -7,11 +7,14 @@ using Microsoft.Extensions.Logging;
|
|||
using Sample.SqlServer.DbContexts;
|
||||
using Sample.SqlServer.Shardings;
|
||||
using ShardingCore;
|
||||
using ShardingCore.Sharding.ReadWriteConfigurations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.EntityFrameworkCore.Query;
|
||||
using Microsoft.EntityFrameworkCore.Query.Internal;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using ShardingCore.Core;
|
||||
using ShardingCore.Core.NotSupportShardingProviders;
|
||||
using ShardingCore.Sharding.ShardingExecutors.Abstractions;
|
||||
using ShardingCore.TableExists;
|
||||
|
@ -60,7 +63,8 @@ namespace Sample.SqlServer
|
|||
});
|
||||
op.ReplaceTableEnsureManager(sp => new SqlServerTableEnsureManager<DefaultShardingDbContext>());
|
||||
op.AddDefaultDataSource("A",
|
||||
"Data Source=localhost;Initial Catalog=ShardingCoreDBXA;Integrated Security=True;"
|
||||
// "Data Source=localhost;Initial Catalog=ShardingCoreDBXA;Integrated Security=True;"
|
||||
"Data Source = 101.37.117.55;persist security info=True;Initial Catalog=ShardingCoreDBXA;uid=sa;pwd=xjmumixl7610#;Max Pool Size=100;"
|
||||
);
|
||||
}).EnsureConfig();
|
||||
services.TryAddSingleton<INotSupportShardingProvider, UnionSupportShardingProvider>();
|
||||
|
|
|
@ -5,16 +5,32 @@ using System.Reflection;
|
|||
using System.Text;
|
||||
using System.Threading;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ShardingCore.Core.EntityMetadatas;
|
||||
using ShardingCore.Core.PhysicTables;
|
||||
using ShardingCore.Core.ShardingConfigurations;
|
||||
using ShardingCore.Core.ShardingConfigurations.Abstractions;
|
||||
using ShardingCore.Core.TrackerManagers;
|
||||
using ShardingCore.Core.VirtualDatabase;
|
||||
using ShardingCore.Core.VirtualDatabase.VirtualDataSources;
|
||||
using ShardingCore.Core.VirtualDatabase.VirtualDataSources.Abstractions;
|
||||
using ShardingCore.Core.VirtualDatabase.VirtualDataSources.PhysicDataSources;
|
||||
using ShardingCore.Core.VirtualDatabase.VirtualTables;
|
||||
using ShardingCore.Core.VirtualRoutes.DataSourceRoutes;
|
||||
using ShardingCore.Core.VirtualRoutes.TableRoutes;
|
||||
using ShardingCore.Core.VirtualRoutes.TableRoutes.RouteTails.Abstractions;
|
||||
using ShardingCore.Core.VirtualTables;
|
||||
using ShardingCore.DynamicDataSources;
|
||||
using ShardingCore.Exceptions;
|
||||
using ShardingCore.Extensions;
|
||||
using ShardingCore.Jobs;
|
||||
using ShardingCore.Jobs.Abstaractions;
|
||||
using ShardingCore.Sharding.Abstractions;
|
||||
using ShardingCore.Sharding.ParallelTables;
|
||||
using ShardingCore.TableCreator;
|
||||
using ShardingCore.Utils;
|
||||
|
||||
/*
|
||||
* @Author: xjm
|
||||
|
@ -77,16 +93,15 @@ namespace ShardingCore.Bootstrapers
|
|||
|
||||
private void InitializeEntityMetadata()
|
||||
{
|
||||
var allVirtualDataSources = _virtualDataSourceManager.GetAllVirtualDataSources();
|
||||
if (allVirtualDataSources.IsEmpty())
|
||||
throw new ShardingCoreConfigException($"must config one virtual data source,db context type :[{typeof(TShardingDbContext)}]");
|
||||
using (var serviceScope = ShardingContainer.ServiceProvider.CreateScope())
|
||||
{
|
||||
var configId = allVirtualDataSources.First().ConfigId;
|
||||
var configId = _virtualDataSourceManager.GetAllVirtualDataSources().First().ConfigId;
|
||||
using (_virtualDataSourceManager.CreateScope(configId))
|
||||
{
|
||||
//var dataSourceName = _virtualDataSource.DefaultDataSourceName;
|
||||
using var context =serviceScope.ServiceProvider.GetRequiredService<TShardingDbContext>();
|
||||
|
||||
using var context =
|
||||
(DbContext)serviceScope.ServiceProvider.GetService(_shardingDbContextType);
|
||||
foreach (var entity in context.Model.GetEntityTypes())
|
||||
{
|
||||
var entityType = entity.ClrType;
|
||||
|
@ -102,6 +117,8 @@ namespace ShardingCore.Bootstrapers
|
|||
}
|
||||
}
|
||||
}
|
||||
//if (_shardingConfigOption.EnsureCreatedWithOutShardingTable)
|
||||
// EnsureCreated(context, dataSourceName);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace ShardingCore.Core.NotSupportShardingProviders
|
|||
public interface INotSupportShardingProvider
|
||||
{
|
||||
void CheckNotSupportSharding(IQueryCompilerContext queryCompilerContext);
|
||||
[Obsolete("not implement this method return any value,plz use NotSupport() eg. dbcontext.Set<User>().NotSupport().Where(...).ToList()")]
|
||||
[Obsolete("plz use NotSupport() eg. dbcontext.Set<User>().NotSupport().Where(...).ToList()")]
|
||||
bool IsNotSupportSharding(IQueryCompilerContext queryCompilerContext);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -147,7 +147,9 @@ namespace ShardingCore.Sharding.ShardingDbContextExecutors
|
|||
|
||||
public static DbContextOptionsBuilder<TShardingDbContext> CreateDbContextOptionBuilder()
|
||||
{
|
||||
return new DbContextOptionsBuilder<TShardingDbContext>();
|
||||
Type type = typeof(DbContextOptionsBuilder<>);
|
||||
type = type.MakeGenericType(typeof(TShardingDbContext));
|
||||
return (DbContextOptionsBuilder<TShardingDbContext>)Activator.CreateInstance(type);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Reference in New Issue