优化顺序查询,支持max和min也支持顺序查询

This commit is contained in:
xuejiaming 2022-01-27 16:13:28 +08:00
parent e53b7d4e59
commit 09c2dcee96
6 changed files with 21 additions and 20 deletions

View File

@ -1,9 +1,9 @@
:start
::定义版本
set EFCORE2=2.4.1.01
set EFCORE3=3.4.1.01
set EFCORE5=5.4.1.01
set EFCORE6=6.4.1.01
set EFCORE2=2.4.1.02
set EFCORE3=3.4.1.02
set EFCORE5=5.4.1.02
set EFCORE6=6.4.1.02
::删除所有bin与obj下的文件
@echo off

View File

@ -27,7 +27,7 @@ namespace Sample.SqlServer.Shardings
#region
builder.ShardingTailComparer(Comparer<string>.Default, false);
builder.ShardingTailComparer(Comparer<string>.Default, false);//表示他是倒叙
//DateOfMonth的排序和月份分片的后缀一致所以用true如果false,无果无关就不需要配置
builder.AddOrder(o => o.DateOfMonth, false);
builder.AddDefaultSequenceQueryTrip(false, CircuitBreakerMethodNameEnum.FirstOrDefault);

View File

@ -36,10 +36,15 @@ namespace ShardingCore.Sharding.EntityQueryConfigurations
}
/// <summary>
/// 使用当前属性order和comparer有关联
/// ShardingTailComparer参数 tailComparer如果是正序,reverse是false那么表示ShardingTailComparer最后采用倒序
/// isSameAsShardingTailComparer,true表示当前添加的属性也是采用倒序,false表示当前添加的属性使用正序
/// 如果不添加AddOrder方法默认采用ShardingTailComparer在这个例子里就是倒序
/// </summary>
/// <typeparam name="TProperty"></typeparam>
/// <param name="primaryOrderPropertyExpression"></param>
/// <param name="isSameAsShardingTailComparer">true:当前属性正序和comparer正序一样,false:当前属性倒序和comparer正序一样</param>
/// <param name="isSameAsShardingTailComparer">
/// true:当前属性正序和comparer正序一样,false:当前属性倒序和comparer正序一样
/// </param>
/// <returns></returns>
public EntityQueryBuilder<TEntity> AddOrder<TProperty>(Expression<Func<TEntity, TProperty>> primaryOrderPropertyExpression,bool isSameAsShardingTailComparer = true)
{

View File

@ -21,9 +21,7 @@ namespace ShardingCore.Sharding.EntityQueryConfigurations
{ CircuitBreakerMethodNameEnum.SingleOrDefault, nameof(Queryable.SingleOrDefault) },
{ CircuitBreakerMethodNameEnum.Any, nameof(Queryable.Any) },
{ CircuitBreakerMethodNameEnum.All, nameof(Queryable.All) },
{ CircuitBreakerMethodNameEnum.Contains, nameof(Queryable.Contains) },
{ CircuitBreakerMethodNameEnum.Max, nameof(Queryable.Max) },
{ CircuitBreakerMethodNameEnum.Min, nameof(Queryable.Min) }
{ CircuitBreakerMethodNameEnum.Contains, nameof(Queryable.Contains) }
};
LimitMethodNameSupports = new Dictionary<LimitMethodNameEnum, string>()
{

View File

@ -16,9 +16,7 @@ namespace ShardingCore.Sharding.EntityQueryConfigurations
SingleOrDefault,
Any,
All,
Contains,
Max,
Min
Contains
}
public enum LimitMethodNameEnum
{

View File

@ -206,8 +206,13 @@ namespace ShardingCore.Sharding
}
}
}
//Max和Min不受order影响
if (virtualTable.EnableEntityQuery && methodName != null &&
virtualTable.EntityQueryMetadata.TryGetDefaultSequenceQueryTrip(methodName, out var defaultAsc))
{
tailComparerIsAsc = defaultAsc;
return true;
}
//Max和Min
if (nameof(Queryable.Max) == methodName || nameof(Queryable.Min) == methodName)
{
//如果是max或者min
@ -217,12 +222,7 @@ namespace ShardingCore.Sharding
return true;
}
}
if (virtualTable.EnableEntityQuery && methodName != null &&
virtualTable.EntityQueryMetadata.TryGetDefaultSequenceQueryTrip(methodName, out var defaultAsc))
{
tailComparerIsAsc = defaultAsc;
return true;
}
tailComparerIsAsc = true;
return false;
}