修复bug支持order by的时候存在简单的convert强转 移除构造函数强日志依赖
This commit is contained in:
parent
aaed91b0b8
commit
04ec7a4671
|
@ -104,7 +104,7 @@ namespace Sample.MySql
|
||||||
// {
|
// {
|
||||||
// conn.Open();
|
// conn.Open();
|
||||||
// }
|
// }
|
||||||
// // DynamicShardingHelper.DynamicAppendDataSource<DefaultShardingDbContext>($"c0",$"ds{i}",$"server=127.0.0.1;port=3306;database=dbdbd{i};userid=root;password=root;");
|
// DynamicShardingHelper.DynamicAppendDataSource<DefaultShardingDbContext>($"c0",$"ds{i}",$"server=127.0.0.1;port=3306;database=dbdbd{i};userid=root;password=root;");
|
||||||
//
|
//
|
||||||
// }
|
// }
|
||||||
app.DbSeed();
|
app.DbSeed();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Information",
|
"Default": "Debug",
|
||||||
"Microsoft": "Warning",
|
"Microsoft": "Warning",
|
||||||
"Microsoft.Hosting.Lifetime": "Information"
|
"Microsoft.Hosting.Lifetime": "Information"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Information",
|
"Default": "Debug",
|
||||||
"Microsoft": "Information",
|
"Microsoft": "Information",
|
||||||
"Microsoft.Hosting.Lifetime": "Information"
|
"Microsoft.Hosting.Lifetime": "Information"
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ using ShardingCore.Extensions;
|
||||||
using ShardingCore.Helpers;
|
using ShardingCore.Helpers;
|
||||||
using ShardingCore.Jobs;
|
using ShardingCore.Jobs;
|
||||||
using ShardingCore.Jobs.Abstaractions;
|
using ShardingCore.Jobs.Abstaractions;
|
||||||
|
using ShardingCore.Logger;
|
||||||
using ShardingCore.Sharding.Abstractions;
|
using ShardingCore.Sharding.Abstractions;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -36,6 +37,7 @@ namespace ShardingCore.Bootstrappers
|
||||||
/// <typeparam name="TEntity"></typeparam>
|
/// <typeparam name="TEntity"></typeparam>
|
||||||
public class EntityMetadataInitializer<TShardingDbContext,TEntity>: IEntityMetadataInitializer where TShardingDbContext:DbContext,IShardingDbContext where TEntity:class
|
public class EntityMetadataInitializer<TShardingDbContext,TEntity>: IEntityMetadataInitializer where TShardingDbContext:DbContext,IShardingDbContext where TEntity:class
|
||||||
{
|
{
|
||||||
|
private static readonly ILogger<EntityMetadataInitializer<TShardingDbContext, TEntity>> _logger=InternalLoggerFactory.CreateLogger<EntityMetadataInitializer<TShardingDbContext,TEntity>>();
|
||||||
private const string QueryFilter = "QueryFilter";
|
private const string QueryFilter = "QueryFilter";
|
||||||
private readonly IEntityType _entityType;
|
private readonly IEntityType _entityType;
|
||||||
private readonly string _virtualTableName;
|
private readonly string _virtualTableName;
|
||||||
|
@ -45,15 +47,13 @@ namespace ShardingCore.Bootstrappers
|
||||||
private readonly IVirtualDataSourceRouteManager<TShardingDbContext> _virtualDataSourceRouteManager;
|
private readonly IVirtualDataSourceRouteManager<TShardingDbContext> _virtualDataSourceRouteManager;
|
||||||
private readonly IVirtualTableManager<TShardingDbContext> _virtualTableManager;
|
private readonly IVirtualTableManager<TShardingDbContext> _virtualTableManager;
|
||||||
private readonly IEntityMetadataManager<TShardingDbContext> _entityMetadataManager;
|
private readonly IEntityMetadataManager<TShardingDbContext> _entityMetadataManager;
|
||||||
private readonly ILogger<EntityMetadataInitializer<TShardingDbContext, TEntity>> _logger;
|
|
||||||
|
|
||||||
public EntityMetadataInitializer(EntityMetadataEnsureParams entityMetadataEnsureParams,
|
public EntityMetadataInitializer(EntityMetadataEnsureParams entityMetadataEnsureParams,
|
||||||
IShardingEntityConfigOptions<TShardingDbContext> shardingEntityConfigOptions,
|
IShardingEntityConfigOptions<TShardingDbContext> shardingEntityConfigOptions,
|
||||||
IVirtualDataSourceManager<TShardingDbContext> virtualDataSourceManager,
|
IVirtualDataSourceManager<TShardingDbContext> virtualDataSourceManager,
|
||||||
IVirtualDataSourceRouteManager<TShardingDbContext> virtualDataSourceRouteManager,
|
IVirtualDataSourceRouteManager<TShardingDbContext> virtualDataSourceRouteManager,
|
||||||
IVirtualTableManager<TShardingDbContext> virtualTableManager,
|
IVirtualTableManager<TShardingDbContext> virtualTableManager,
|
||||||
IEntityMetadataManager<TShardingDbContext> entityMetadataManager,
|
IEntityMetadataManager<TShardingDbContext> entityMetadataManager
|
||||||
ILogger<EntityMetadataInitializer<TShardingDbContext, TEntity>> logger
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
_entityType = entityMetadataEnsureParams.EntityType;
|
_entityType = entityMetadataEnsureParams.EntityType;
|
||||||
|
@ -64,7 +64,6 @@ namespace ShardingCore.Bootstrappers
|
||||||
_virtualDataSourceRouteManager = virtualDataSourceRouteManager;
|
_virtualDataSourceRouteManager = virtualDataSourceRouteManager;
|
||||||
_virtualTableManager = virtualTableManager;
|
_virtualTableManager = virtualTableManager;
|
||||||
_entityMetadataManager = entityMetadataManager;
|
_entityMetadataManager = entityMetadataManager;
|
||||||
_logger = logger;
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 初始化
|
/// 初始化
|
||||||
|
|
|
@ -16,27 +16,29 @@ using ShardingCore.TableCreator;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using ShardingCore.Logger;
|
||||||
|
|
||||||
namespace ShardingCore.DynamicDataSources
|
namespace ShardingCore.DynamicDataSources
|
||||||
{
|
{
|
||||||
public class DataSourceInitializer<TShardingDbContext> : IDataSourceInitializer<TShardingDbContext>
|
public class DataSourceInitializer<TShardingDbContext> : IDataSourceInitializer<TShardingDbContext>
|
||||||
where TShardingDbContext : DbContext, IShardingDbContext
|
where TShardingDbContext : DbContext, IShardingDbContext
|
||||||
{
|
{
|
||||||
|
private static readonly ILogger<DataSourceInitializer<TShardingDbContext>> _logger =
|
||||||
|
InternalLoggerFactory.CreateLogger<DataSourceInitializer<TShardingDbContext>>();
|
||||||
|
|
||||||
private readonly IShardingEntityConfigOptions<TShardingDbContext> _entityConfigOptions;
|
private readonly IShardingEntityConfigOptions<TShardingDbContext> _entityConfigOptions;
|
||||||
private readonly IVirtualDataSourceManager<TShardingDbContext> _virtualDataSourceManager;
|
private readonly IVirtualDataSourceManager<TShardingDbContext> _virtualDataSourceManager;
|
||||||
private readonly IRouteTailFactory _routeTailFactory;
|
private readonly IRouteTailFactory _routeTailFactory;
|
||||||
private readonly IVirtualTableManager<TShardingDbContext> _virtualTableManager;
|
private readonly IVirtualTableManager<TShardingDbContext> _virtualTableManager;
|
||||||
private readonly IEntityMetadataManager<TShardingDbContext> _entityMetadataManager;
|
private readonly IEntityMetadataManager<TShardingDbContext> _entityMetadataManager;
|
||||||
private readonly IShardingTableCreator<TShardingDbContext> _tableCreator;
|
private readonly IShardingTableCreator<TShardingDbContext> _tableCreator;
|
||||||
private readonly ILogger<DataSourceInitializer<TShardingDbContext>> _logger;
|
|
||||||
|
|
||||||
public DataSourceInitializer(
|
public DataSourceInitializer(
|
||||||
IShardingEntityConfigOptions<TShardingDbContext> entityConfigOptions,
|
IShardingEntityConfigOptions<TShardingDbContext> entityConfigOptions,
|
||||||
IVirtualDataSourceManager<TShardingDbContext> virtualDataSourceManager,
|
IVirtualDataSourceManager<TShardingDbContext> virtualDataSourceManager,
|
||||||
IRouteTailFactory routeTailFactory, IVirtualTableManager<TShardingDbContext> virtualTableManager,
|
IRouteTailFactory routeTailFactory, IVirtualTableManager<TShardingDbContext> virtualTableManager,
|
||||||
IEntityMetadataManager<TShardingDbContext> entityMetadataManager,
|
IEntityMetadataManager<TShardingDbContext> entityMetadataManager,
|
||||||
IShardingTableCreator<TShardingDbContext> shardingTableCreator,
|
IShardingTableCreator<TShardingDbContext> shardingTableCreator)
|
||||||
ILogger<DataSourceInitializer<TShardingDbContext>> logger)
|
|
||||||
{
|
{
|
||||||
_entityConfigOptions = entityConfigOptions;
|
_entityConfigOptions = entityConfigOptions;
|
||||||
_virtualDataSourceManager = virtualDataSourceManager;
|
_virtualDataSourceManager = virtualDataSourceManager;
|
||||||
|
@ -44,7 +46,6 @@ namespace ShardingCore.DynamicDataSources
|
||||||
_virtualTableManager = virtualTableManager;
|
_virtualTableManager = virtualTableManager;
|
||||||
_entityMetadataManager = entityMetadataManager;
|
_entityMetadataManager = entityMetadataManager;
|
||||||
_tableCreator = shardingTableCreator;
|
_tableCreator = shardingTableCreator;
|
||||||
_logger = logger;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InitConfigure(IVirtualDataSource<TShardingDbContext> virtualDataSource, string dataSourceName,
|
public void InitConfigure(IVirtualDataSource<TShardingDbContext> virtualDataSource, string dataSourceName,
|
||||||
|
|
|
@ -17,6 +17,7 @@ using ShardingCore.Core.DbContextCreator;
|
||||||
using ShardingCore.Exceptions;
|
using ShardingCore.Exceptions;
|
||||||
using ShardingCore.Extensions;
|
using ShardingCore.Extensions;
|
||||||
using ShardingCore.Infrastructures;
|
using ShardingCore.Infrastructures;
|
||||||
|
using ShardingCore.Logger;
|
||||||
using ShardingCore.Sharding.Abstractions;
|
using ShardingCore.Sharding.Abstractions;
|
||||||
|
|
||||||
namespace ShardingCore.Sharding.ShardingDbContextExecutors
|
namespace ShardingCore.Sharding.ShardingDbContextExecutors
|
||||||
|
@ -28,25 +29,34 @@ namespace ShardingCore.Sharding.ShardingDbContextExecutors
|
||||||
* @Ver: 1.0
|
* @Ver: 1.0
|
||||||
* @Email: 326308290@qq.com
|
* @Email: 326308290@qq.com
|
||||||
*/
|
*/
|
||||||
public class DataSourceDbContext<TShardingDbContext> : IDataSourceDbContext where TShardingDbContext : DbContext, IShardingDbContext
|
public class DataSourceDbContext<TShardingDbContext> : IDataSourceDbContext
|
||||||
|
where TShardingDbContext : DbContext, IShardingDbContext
|
||||||
{
|
{
|
||||||
|
private static readonly ILogger<DataSourceDbContext<TShardingDbContext>> _logger =
|
||||||
|
InternalLoggerFactory.CreateLogger<DataSourceDbContext<TShardingDbContext>>();
|
||||||
|
|
||||||
private static readonly IComparer<string> _comparer = new NoShardingFirstComparer();
|
private static readonly IComparer<string> _comparer = new NoShardingFirstComparer();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 当前是否是默认的dbcontext 也就是不分片的dbcontext
|
/// 当前是否是默认的dbcontext 也就是不分片的dbcontext
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsDefault { get; }
|
public bool IsDefault { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 当前同库有多少dbcontext了
|
/// 当前同库有多少dbcontext了
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int DbContextCount => _dataSourceDbContexts.Count;
|
public int DbContextCount => _dataSourceDbContexts.Count;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// dbcontext 创建接口
|
/// dbcontext 创建接口
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly IDbContextCreator<TShardingDbContext> _dbContextCreator;
|
private readonly IDbContextCreator<TShardingDbContext> _dbContextCreator;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 实际的链接字符串管理者 用来提供查询和插入dbcontext的创建链接的获取
|
/// 实际的链接字符串管理者 用来提供查询和插入dbcontext的创建链接的获取
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly ActualConnectionStringManager<TShardingDbContext> _actualConnectionStringManager;
|
private readonly ActualConnectionStringManager<TShardingDbContext> _actualConnectionStringManager;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 当前的数据源是什么默认单数据源可以支持多数据源配置
|
/// 当前的数据源是什么默认单数据源可以支持多数据源配置
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -56,6 +66,7 @@ namespace ShardingCore.Sharding.ShardingDbContextExecutors
|
||||||
/// 数据源名称
|
/// 数据源名称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string DataSourceName { get; }
|
public string DataSourceName { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 数据源排序默认提交将未分片的数据库最先提交
|
/// 数据源排序默认提交将未分片的数据库最先提交
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -66,21 +77,23 @@ namespace ShardingCore.Sharding.ShardingDbContextExecutors
|
||||||
/// 是否开启了事务
|
/// 是否开启了事务
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private bool _isBeginTransaction => _shardingShellDbContext.Database.CurrentTransaction != null;
|
private bool _isBeginTransaction => _shardingShellDbContext.Database.CurrentTransaction != null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// shell dbcontext最外面的壳
|
/// shell dbcontext最外面的壳
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly DbContext _shardingShellDbContext;
|
private readonly DbContext _shardingShellDbContext;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 数据库事务
|
/// 数据库事务
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private IDbContextTransaction _shardingContextTransaction => _shardingShellDbContext?.Database?.CurrentTransaction;
|
private IDbContextTransaction _shardingContextTransaction =>
|
||||||
|
_shardingShellDbContext?.Database?.CurrentTransaction;
|
||||||
|
|
||||||
|
|
||||||
private readonly ILogger<DataSourceDbContext<TShardingDbContext>> _logger;
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 同库下公用一个db context options
|
/// 同库下公用一个db context options
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private DbContextOptions<TShardingDbContext> _dbContextOptions;
|
private DbContextOptions<TShardingDbContext> _dbContextOptions;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否触发了并发如果是的话就报错
|
/// 是否触发了并发如果是的话就报错
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -108,12 +121,13 @@ namespace ShardingCore.Sharding.ShardingDbContextExecutors
|
||||||
DataSourceName = dataSourceName;
|
DataSourceName = dataSourceName;
|
||||||
IsDefault = isDefault;
|
IsDefault = isDefault;
|
||||||
_shardingShellDbContext = shardingShellDbContext;
|
_shardingShellDbContext = shardingShellDbContext;
|
||||||
_virtualDataSource = (IVirtualDataSource<TShardingDbContext>)((IShardingDbContext)shardingShellDbContext).GetVirtualDataSource();
|
_virtualDataSource =
|
||||||
|
(IVirtualDataSource<TShardingDbContext>)((IShardingDbContext)shardingShellDbContext)
|
||||||
|
.GetVirtualDataSource();
|
||||||
_dbContextCreator = dbContextCreator;
|
_dbContextCreator = dbContextCreator;
|
||||||
_actualConnectionStringManager = actualConnectionStringManager;
|
_actualConnectionStringManager = actualConnectionStringManager;
|
||||||
_logger = ShardingContainer.GetService<ILogger<DataSourceDbContext<TShardingDbContext>>>();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建共享的数据源配置用来做事务 不支持并发后期发现直接报错
|
/// 创建共享的数据源配置用来做事务 不支持并发后期发现直接报错
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -124,12 +138,14 @@ namespace ShardingCore.Sharding.ShardingDbContextExecutors
|
||||||
{
|
{
|
||||||
return _dbContextOptions;
|
return _dbContextOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
//是否触发并发了
|
//是否触发并发了
|
||||||
var acquired = oneByOne.Start();
|
var acquired = oneByOne.Start();
|
||||||
if (!acquired)
|
if (!acquired)
|
||||||
{
|
{
|
||||||
throw new ShardingCoreException("cant parallel create CreateShareDbContextOptionsBuilder");
|
throw new ShardingCoreException("cant parallel create CreateShareDbContextOptionsBuilder");
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//先创建dbcontext option builder
|
//先创建dbcontext option builder
|
||||||
|
@ -168,7 +184,6 @@ namespace ShardingCore.Sharding.ShardingDbContextExecutors
|
||||||
{
|
{
|
||||||
oneByOne.Stop();
|
oneByOne.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DbContextOptionsBuilder<TShardingDbContext> CreateDbContextOptionBuilder()
|
public static DbContextOptionsBuilder<TShardingDbContext> CreateDbContextOptionBuilder()
|
||||||
|
@ -193,10 +208,12 @@ namespace ShardingCore.Sharding.ShardingDbContextExecutors
|
||||||
var cacheKey = routeTail.GetRouteTailIdentity();
|
var cacheKey = routeTail.GetRouteTailIdentity();
|
||||||
if (!_dataSourceDbContexts.TryGetValue(cacheKey, out var dbContext))
|
if (!_dataSourceDbContexts.TryGetValue(cacheKey, out var dbContext))
|
||||||
{
|
{
|
||||||
dbContext = _dbContextCreator.CreateDbContext(_shardingShellDbContext,CreateShareDbContextOptionsBuilder(), routeTail);
|
dbContext = _dbContextCreator.CreateDbContext(_shardingShellDbContext,
|
||||||
|
CreateShareDbContextOptionsBuilder(), routeTail);
|
||||||
_dataSourceDbContexts.Add(cacheKey, dbContext);
|
_dataSourceDbContexts.Add(cacheKey, dbContext);
|
||||||
ShardingDbTransaction();
|
ShardingDbTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
return dbContext;
|
return dbContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,6 +225,7 @@ namespace ShardingCore.Sharding.ShardingDbContextExecutors
|
||||||
JoinCurrentTransaction();
|
JoinCurrentTransaction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 加入到当前事务
|
/// 加入到当前事务
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -246,6 +264,7 @@ namespace ShardingCore.Sharding.ShardingDbContextExecutors
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 通知事务自动管理是否要清理还是开启还是加入事务
|
/// 通知事务自动管理是否要清理还是开启还是加入事务
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -261,6 +280,7 @@ namespace ShardingCore.Sharding.ShardingDbContextExecutors
|
||||||
JoinCurrentTransaction();
|
JoinCurrentTransaction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 清理事务
|
/// 清理事务
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -288,15 +308,16 @@ namespace ShardingCore.Sharding.ShardingDbContextExecutors
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 异步提交
|
/// 异步提交
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="acceptAllChangesOnSuccess"></param>
|
/// <param name="acceptAllChangesOnSuccess"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<int> SaveChangesAsync(bool acceptAllChangesOnSuccess, CancellationToken cancellationToken = new CancellationToken())
|
public async Task<int> SaveChangesAsync(bool acceptAllChangesOnSuccess,
|
||||||
|
CancellationToken cancellationToken = new CancellationToken())
|
||||||
{
|
{
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
foreach (var dataSourceDbContext in _dataSourceDbContexts)
|
foreach (var dataSourceDbContext in _dataSourceDbContexts)
|
||||||
{
|
{
|
||||||
|
@ -305,6 +326,7 @@ namespace ShardingCore.Sharding.ShardingDbContextExecutors
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取当前的后缀数据库字典数据
|
/// 获取当前的后缀数据库字典数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -313,6 +335,7 @@ namespace ShardingCore.Sharding.ShardingDbContextExecutors
|
||||||
{
|
{
|
||||||
return _dataSourceDbContexts;
|
return _dataSourceDbContexts;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 回滚数据
|
/// 回滚数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -329,6 +352,7 @@ namespace ShardingCore.Sharding.ShardingDbContextExecutors
|
||||||
_logger.LogError(e, "rollback error.");
|
_logger.LogError(e, "rollback error.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 提交数据
|
/// 提交数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -349,7 +373,6 @@ namespace ShardingCore.Sharding.ShardingDbContextExecutors
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if !EFCORE2
|
#if !EFCORE2
|
||||||
|
|
||||||
public async Task RollbackAsync(CancellationToken cancellationToken = new CancellationToken())
|
public async Task RollbackAsync(CancellationToken cancellationToken = new CancellationToken())
|
||||||
{
|
{
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
@ -366,7 +389,8 @@ namespace ShardingCore.Sharding.ShardingDbContextExecutors
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task CommitAsync(int dataSourceCount, CancellationToken cancellationToken = new CancellationToken())
|
public async Task CommitAsync(int dataSourceCount, CancellationToken cancellationToken =
|
||||||
|
new CancellationToken())
|
||||||
{
|
{
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
if (IsDefault)
|
if (IsDefault)
|
||||||
|
@ -393,7 +417,6 @@ namespace ShardingCore.Sharding.ShardingDbContextExecutors
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if !EFCORE2
|
#if !EFCORE2
|
||||||
|
|
||||||
public async ValueTask DisposeAsync()
|
public async ValueTask DisposeAsync()
|
||||||
{
|
{
|
||||||
foreach (var dataSourceDbContext in _dataSourceDbContexts)
|
foreach (var dataSourceDbContext in _dataSourceDbContexts)
|
||||||
|
|
|
@ -5,6 +5,7 @@ using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using ShardingCore.Extensions;
|
using ShardingCore.Extensions;
|
||||||
|
using ShardingCore.Logger;
|
||||||
using ShardingCore.Sharding.Parsers.Abstractions;
|
using ShardingCore.Sharding.Parsers.Abstractions;
|
||||||
using ShardingCore.Sharding.ShardingExecutors.Abstractions;
|
using ShardingCore.Sharding.ShardingExecutors.Abstractions;
|
||||||
using ShardingCore.Sharding.Visitors.ShardingExtractParameters;
|
using ShardingCore.Sharding.Visitors.ShardingExtractParameters;
|
||||||
|
@ -17,15 +18,14 @@ namespace ShardingCore.Sharding.ShardingExecutors
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class DefaultShardingCompilerExecutor: IShardingCompilerExecutor
|
public class DefaultShardingCompilerExecutor: IShardingCompilerExecutor
|
||||||
{
|
{
|
||||||
private readonly ILogger<DefaultShardingCompilerExecutor> _logger;
|
private static readonly ILogger<DefaultShardingCompilerExecutor> _logger=InternalLoggerFactory.CreateLogger<DefaultShardingCompilerExecutor>();
|
||||||
private readonly IShardingTrackQueryExecutor _shardingTrackQueryExecutor;
|
private readonly IShardingTrackQueryExecutor _shardingTrackQueryExecutor;
|
||||||
private readonly IQueryCompilerContextFactory _queryCompilerContextFactory;
|
private readonly IQueryCompilerContextFactory _queryCompilerContextFactory;
|
||||||
private readonly IPrepareParser _prepareParser;
|
private readonly IPrepareParser _prepareParser;
|
||||||
|
|
||||||
public DefaultShardingCompilerExecutor(ILogger<DefaultShardingCompilerExecutor> logger,
|
public DefaultShardingCompilerExecutor(
|
||||||
IShardingTrackQueryExecutor shardingTrackQueryExecutor, IQueryCompilerContextFactory queryCompilerContextFactory,IPrepareParser prepareParser)
|
IShardingTrackQueryExecutor shardingTrackQueryExecutor, IQueryCompilerContextFactory queryCompilerContextFactory,IPrepareParser prepareParser)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
|
||||||
_shardingTrackQueryExecutor = shardingTrackQueryExecutor;
|
_shardingTrackQueryExecutor = shardingTrackQueryExecutor;
|
||||||
_queryCompilerContextFactory = queryCompilerContextFactory;
|
_queryCompilerContextFactory = queryCompilerContextFactory;
|
||||||
_prepareParser = prepareParser;
|
_prepareParser = prepareParser;
|
||||||
|
|
|
@ -14,6 +14,7 @@ using System.Threading.Tasks;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using ShardingCore.Core;
|
using ShardingCore.Core;
|
||||||
using ShardingCore.Extensions.InternalExtensions;
|
using ShardingCore.Extensions.InternalExtensions;
|
||||||
|
using ShardingCore.Logger;
|
||||||
#if EFCORE2
|
#if EFCORE2
|
||||||
using Microsoft.EntityFrameworkCore.Internal;
|
using Microsoft.EntityFrameworkCore.Internal;
|
||||||
#endif
|
#endif
|
||||||
|
@ -29,12 +30,8 @@ namespace ShardingCore.Sharding.ShardingQueryExecutors
|
||||||
*/
|
*/
|
||||||
public class DefaultShardingQueryExecutor : IShardingQueryExecutor
|
public class DefaultShardingQueryExecutor : IShardingQueryExecutor
|
||||||
{
|
{
|
||||||
private readonly ILogger<DefaultShardingQueryExecutor> _logger;
|
private static readonly ILogger<DefaultShardingQueryExecutor> _logger=InternalLoggerFactory.CreateLogger<DefaultShardingQueryExecutor>();
|
||||||
|
|
||||||
public DefaultShardingQueryExecutor(ILogger<DefaultShardingQueryExecutor> logger)
|
|
||||||
{
|
|
||||||
_logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TResult Execute<TResult>(IMergeQueryCompilerContext mergeQueryCompilerContext)
|
public TResult Execute<TResult>(IMergeQueryCompilerContext mergeQueryCompilerContext)
|
||||||
{
|
{
|
||||||
|
|
|
@ -62,7 +62,19 @@ namespace ShardingCore.Core.Internal.Visitors
|
||||||
{
|
{
|
||||||
if (typeof(IOrderedQueryable).IsAssignableFrom(node.Type))
|
if (typeof(IOrderedQueryable).IsAssignableFrom(node.Type))
|
||||||
{
|
{
|
||||||
var expression = (((node.Arguments[1] as UnaryExpression).Operand as LambdaExpression).Body as MemberExpression);
|
MemberExpression expression =null;
|
||||||
|
var orderbody = ((node.Arguments[1] as UnaryExpression).Operand as LambdaExpression).Body;
|
||||||
|
if(orderbody is MemberExpression orderMemberExpression)
|
||||||
|
{
|
||||||
|
expression = orderMemberExpression;
|
||||||
|
}
|
||||||
|
else if (orderbody.NodeType == ExpressionType.Convert&&orderbody is UnaryExpression orderUnaryExpression)
|
||||||
|
{
|
||||||
|
if(orderUnaryExpression.Operand is MemberExpression orderMemberConvertExpression)
|
||||||
|
{
|
||||||
|
expression = orderMemberConvertExpression;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (expression == null)
|
if (expression == null)
|
||||||
throw new NotSupportedException("sharding order not support ");
|
throw new NotSupportedException("sharding order not support ");
|
||||||
List<string> properties = new List<string>();
|
List<string> properties = new List<string>();
|
||||||
|
|
Loading…
Reference in New Issue