修复分库路由导致的数据名不正确发布x.3.1.26

This commit is contained in:
xuejiaming 2021-11-07 10:41:31 +08:00
parent 542cab3b6a
commit 4f0828d47f
5 changed files with 16 additions and 10 deletions

View File

@ -1,8 +1,8 @@
:start
::定义版本
set EFCORE2=2.3.1.25
set EFCORE3=3.3.1.25
set EFCORE5=5.3.1.25
set EFCORE2=2.3.1.26
set EFCORE3=3.3.1.26
set EFCORE5=5.3.1.26
::删除所有bin与obj下的文件
@echo off

View File

@ -26,7 +26,7 @@ namespace ShardingCore.Core.VirtualRoutes.DataSourceRoutes.Abstractions
protected override List<string> DoRouteWithPredicate(List<string> allDataSourceNames, IQueryable queryable)
{
//获取所有需要路由的表后缀
var filter = ShardingUtil.GetRouteShardingTableFilter(queryable, EntityMetadata, ConvertToShardingKey, GetRouteToFilter);
var filter = ShardingUtil.GetRouteShardingTableFilter(queryable, EntityMetadata, ConvertToShardingKey, GetRouteToFilter,false);
var dataSources = allDataSourceNames.Where(o => filter(o)).ToList();
return dataSources;
}

View File

@ -22,7 +22,7 @@ namespace ShardingCore.Core.VirtualRoutes.TableRoutes.Abstractions
protected override List<IPhysicTable> DoRouteWithPredicate(List<IPhysicTable> allPhysicTables, IQueryable queryable)
{
//获取所有需要路由的表后缀
var filter = ShardingUtil.GetRouteShardingTableFilter(queryable, EntityMetadata, ConvertToShardingKey, GetRouteToFilter);
var filter = ShardingUtil.GetRouteShardingTableFilter(queryable, EntityMetadata, ConvertToShardingKey, GetRouteToFilter,true);
var physicTables = allPhysicTables.Where(o => filter(o.Tail)).ToList();
return physicTables;
}

View File

@ -23,13 +23,18 @@ namespace ShardingCore.Core.Internal.Visitors
private readonly EntityMetadata _entityMetadata;
private readonly Func<object, TKey> _shardingKeyConvert;
private readonly Func<TKey, ShardingOperatorEnum, Expression<Func<string, bool>>> _keyToTailWithFilter;
/// <summary>
/// 是否是分表路由
/// </summary>
private readonly bool _shardingTableRoute;
private Expression<Func<string, bool>> _where = x => true;
public QueryableRouteShardingTableDiscoverVisitor(EntityMetadata entityMetadata, Func<object, TKey> shardingKeyConvert, Func<TKey, ShardingOperatorEnum, Expression<Func<string, bool>>> keyToTailWithFilter)
public QueryableRouteShardingTableDiscoverVisitor(EntityMetadata entityMetadata, Func<object, TKey> shardingKeyConvert, Func<TKey, ShardingOperatorEnum, Expression<Func<string, bool>>> keyToTailWithFilter,bool shardingTableRoute)
{
_entityMetadata = entityMetadata;
_shardingKeyConvert = shardingKeyConvert;
_keyToTailWithFilter = keyToTailWithFilter;
_shardingTableRoute = shardingTableRoute;
}
public Func<string, bool> GetStringFilterTail()
@ -41,7 +46,7 @@ namespace ShardingCore.Core.Internal.Visitors
{
return expression is MemberExpression member
&& member.Expression.Type == _entityMetadata.EntityType
&& member.Member.Name == _entityMetadata.ShardingTableProperty.Name;
&& member.Member.Name == (_shardingTableRoute?_entityMetadata.ShardingTableProperty.Name:_entityMetadata.ShardingDataSourceProperty.Name);
}
/// <summary>
/// 方法是否包含shardingKey
@ -56,7 +61,7 @@ namespace ShardingCore.Core.Internal.Visitors
{
var isShardingKey = methodCallExpression.Arguments[i] is MemberExpression member
&& member.Expression.Type == _entityMetadata.EntityType
&& member.Member.Name == _entityMetadata.ShardingTableProperty.Name;
&& member.Member.Name == (_shardingTableRoute ? _entityMetadata.ShardingTableProperty.Name : _entityMetadata.ShardingDataSourceProperty.Name);
if (isShardingKey) return true;
}
}

View File

@ -49,10 +49,11 @@ namespace ShardingCore.Utils
/// <param name="entityMetadata"></param>
/// <param name="shardingKeyConvert"></param>
/// <param name="keyToTailExpression"></param>
/// <param name="shardingTableRoute">sharding table or data source</param>
/// <returns></returns>
public static Func<string, bool> GetRouteShardingTableFilter<TKey>(IQueryable queryable, EntityMetadata entityMetadata, Func<object, TKey> shardingKeyConvert, Func<TKey, ShardingOperatorEnum, Expression<Func<string, bool>>> keyToTailExpression)
public static Func<string, bool> GetRouteShardingTableFilter<TKey>(IQueryable queryable, EntityMetadata entityMetadata, Func<object, TKey> shardingKeyConvert, Func<TKey, ShardingOperatorEnum, Expression<Func<string, bool>>> keyToTailExpression,bool shardingTableRoute)
{
QueryableRouteShardingTableDiscoverVisitor<TKey> visitor = new QueryableRouteShardingTableDiscoverVisitor<TKey>(entityMetadata, shardingKeyConvert, keyToTailExpression);
QueryableRouteShardingTableDiscoverVisitor<TKey> visitor = new QueryableRouteShardingTableDiscoverVisitor<TKey>(entityMetadata, shardingKeyConvert, keyToTailExpression, shardingTableRoute);
visitor.Visit(queryable.Expression);