修改动态数据源
This commit is contained in:
parent
e78c9f0daf
commit
888ba0ed5a
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue