修改动态数据源

This commit is contained in:
xuejiaming 2021-12-16 14:25:09 +08:00
parent e78c9f0daf
commit 888ba0ed5a
3 changed files with 13 additions and 1 deletions

View File

@ -4,6 +4,9 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Sample.SqlServerShardingAll.Entities;
using ShardingCore;
using ShardingCore.Core.VirtualDatabase.VirtualDataSources;
using ShardingCore.DynamicDataSources;
namespace Sample.SqlServerShardingAll.Controllers
{
@ -19,6 +22,14 @@ namespace Sample.SqlServerShardingAll.Controllers
}
public async Task<IActionResult> Query()
{
#region
//var virtualDataSource = ShardingContainer.GetService<IVirtualDataSource<MyDbContext>>();
//var virtualDataSourceRoute = virtualDataSource.GetRoute(typeof(Order));
//virtualDataSourceRoute.AddDataSourceName("D");
//DynamicDataSourceHelper.DynamicAppendDataSource<MyDbContext>("D", "连接字符串");
#endregion
var sysUser =await _myDbContext.Set<SysUser>().Where(o=>o.Id=="1").FirstOrDefaultAsync();
var sysUserA1 =await _myDbContext.Set<SysUser>().Where(o=>o.Id=="1" && o.Area == "A").FirstOrDefaultAsync();
var dateTime = new DateTime(2021,3,5);

View File

@ -54,7 +54,7 @@ namespace ShardingCore.DynamicDataSources
}
public void InitConfigure(string dataSourceName, string connectionString)
{
InitConfigure(dataSourceName,connectionString, _shardingConfigOption.EnsureCreatedWithOutShardingTable);
InitConfigure(dataSourceName,connectionString, true);
}
public void InitConfigure(string dataSourceName, string connectionString, bool createDatabase)

View File

@ -10,6 +10,7 @@ namespace ShardingCore.DynamicDataSources
{
public interface IDataSourceInitializer<TShardingDbContext> where TShardingDbContext : DbContext, IShardingDbContext
{
[Obsolete("plz use method InitConfigure(string dataSourceName, string connectionString,bool createDatabase)")]
void InitConfigure(string dataSourceName, string connectionString);
void InitConfigure(string dataSourceName, string connectionString,bool createDatabase);
}