发布x.6.0.8
This commit is contained in:
parent
3d409c3c8d
commit
636a643d2c
|
@ -1,9 +1,9 @@
|
||||||
:start
|
:start
|
||||||
::定义版本
|
::定义版本
|
||||||
set EFCORE2=2.6.0.7
|
set EFCORE2=2.6.0.8
|
||||||
set EFCORE3=3.6.0.7
|
set EFCORE3=3.6.0.8
|
||||||
set EFCORE5=5.6.0.7
|
set EFCORE5=5.6.0.8
|
||||||
set EFCORE6=6.6.0.7
|
set EFCORE6=6.6.0.8
|
||||||
|
|
||||||
::删除所有bin与obj下的文件
|
::删除所有bin与obj下的文件
|
||||||
@echo off
|
@echo off
|
||||||
|
|
|
@ -149,7 +149,7 @@ namespace Sample.SqlServerShardingTable.Controllers
|
||||||
|
|
||||||
public async Task<IActionResult> DynamicReadWrite()
|
public async Task<IActionResult> DynamicReadWrite()
|
||||||
{
|
{
|
||||||
DynamicShardingHelper.DynamicAppendReadWriteConnectionString<MyDbContext>(_shardingRuntimeContext,"ds0", "Data Source=localhost;Initial Catalog=EFCoreShardingTableDB1;Integrated Security=True;");
|
DynamicShardingHelper.DynamicAppendReadWriteConnectionString(_shardingRuntimeContext,"ds0", "Data Source=localhost;Initial Catalog=EFCoreShardingTableDB1;Integrated Security=True;");
|
||||||
var sysUser = await _myDbContext.Set<SysUser>().Where(o => o.Id == "1").FirstOrDefaultAsync();
|
var sysUser = await _myDbContext.Set<SysUser>().Where(o => o.Id == "1").FirstOrDefaultAsync();
|
||||||
|
|
||||||
return Ok(sysUser);
|
return Ok(sysUser);
|
||||||
|
|
|
@ -3,14 +3,9 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using ShardingCore.Core.RuntimeContexts;
|
using ShardingCore.Core.RuntimeContexts;
|
||||||
using ShardingCore.Core.VirtualDatabase.VirtualDataSources;
|
|
||||||
using ShardingCore.Core.VirtualDatabase.VirtualDataSources.Abstractions;
|
|
||||||
using ShardingCore.Core.VirtualDatabase.VirtualDataSources.PhysicDataSources;
|
using ShardingCore.Core.VirtualDatabase.VirtualDataSources.PhysicDataSources;
|
||||||
using ShardingCore.DynamicDataSources;
|
|
||||||
using ShardingCore.Exceptions;
|
using ShardingCore.Exceptions;
|
||||||
using ShardingCore.Sharding.Abstractions;
|
|
||||||
using ShardingCore.Sharding.ReadWriteConfigurations.Abstractions;
|
using ShardingCore.Sharding.ReadWriteConfigurations.Abstractions;
|
||||||
|
|
||||||
namespace ShardingCore.Helpers
|
namespace ShardingCore.Helpers
|
||||||
|
@ -25,31 +20,40 @@ namespace ShardingCore.Helpers
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 动态添加数据源
|
/// 动态添加数据源
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="TShardingDbContext"></typeparam>
|
|
||||||
/// <param name="shardingRuntimeContext"></param>
|
/// <param name="shardingRuntimeContext"></param>
|
||||||
/// <param name="dataSourceName"></param>
|
/// <param name="dataSourceName"></param>
|
||||||
/// <param name="connectionString"></param>
|
/// <param name="connectionString"></param>
|
||||||
/// <param name="createDatabase"></param>
|
/// <param name="createDatabase"></param>
|
||||||
/// <param name="createTable"></param>
|
/// <param name="createTable"></param>
|
||||||
public static void DynamicAppendDataSource<TShardingDbContext>(IShardingRuntimeContext shardingRuntimeContext, string dataSourceName, string connectionString,bool createDatabase,bool createTable) where TShardingDbContext : DbContext, IShardingDbContext
|
public static void DynamicAppendDataSource(IShardingRuntimeContext shardingRuntimeContext, string dataSourceName, string connectionString,bool createDatabase,bool createTable)
|
||||||
{
|
{
|
||||||
var virtualDataSource = shardingRuntimeContext.GetVirtualDataSource();
|
var virtualDataSource = shardingRuntimeContext.GetVirtualDataSource();
|
||||||
virtualDataSource.AddPhysicDataSource(new DefaultPhysicDataSource(dataSourceName, connectionString, false));
|
virtualDataSource.AddPhysicDataSource(new DefaultPhysicDataSource(dataSourceName, connectionString, false));
|
||||||
var dataSourceInitializer = shardingRuntimeContext.GetDataSourceInitializer();
|
var dataSourceInitializer = shardingRuntimeContext.GetDataSourceInitializer();
|
||||||
dataSourceInitializer.InitConfigure(dataSourceName,createDatabase,createTable);
|
dataSourceInitializer.InitConfigure(dataSourceName,createDatabase,createTable);
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 动态添加数据源
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="shardingRuntimeContext"></param>
|
||||||
|
/// <param name="dataSourceName"></param>
|
||||||
|
/// <param name="connectionString"></param>
|
||||||
|
public static void DynamicAppendDataSourceOnly(IShardingRuntimeContext shardingRuntimeContext, string dataSourceName, string connectionString)
|
||||||
|
{
|
||||||
|
var virtualDataSource = shardingRuntimeContext.GetVirtualDataSource();
|
||||||
|
virtualDataSource.AddPhysicDataSource(new DefaultPhysicDataSource(dataSourceName, connectionString, false));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 动态添加读写分离链接字符串
|
/// 动态添加读写分离链接字符串
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="TShardingDbContext"></typeparam>
|
|
||||||
/// <param name="shardingRuntimeContext"></param>
|
/// <param name="shardingRuntimeContext"></param>
|
||||||
/// <param name="dataSourceName"></param>
|
/// <param name="dataSourceName"></param>
|
||||||
/// <param name="connectionString"></param>
|
/// <param name="connectionString"></param>
|
||||||
/// <param name="readNodeName"></param>
|
/// <param name="readNodeName"></param>
|
||||||
/// <exception cref="ShardingCoreInvalidOperationException"></exception>
|
/// <exception cref="ShardingCoreInvalidOperationException"></exception>
|
||||||
public static void DynamicAppendReadWriteConnectionString<TShardingDbContext>(IShardingRuntimeContext shardingRuntimeContext, string dataSourceName,
|
public static void DynamicAppendReadWriteConnectionString(IShardingRuntimeContext shardingRuntimeContext, string dataSourceName,
|
||||||
string connectionString, string readNodeName=null) where TShardingDbContext : DbContext, IShardingDbContext
|
string connectionString, string readNodeName=null)
|
||||||
{
|
{
|
||||||
var virtualDataSource = shardingRuntimeContext.GetVirtualDataSource();
|
var virtualDataSource = shardingRuntimeContext.GetVirtualDataSource();
|
||||||
if (virtualDataSource.ConnectionStringManager is IReadWriteConnectionStringManager
|
if (virtualDataSource.ConnectionStringManager is IReadWriteConnectionStringManager
|
||||||
|
|
Loading…
Reference in New Issue