添加CompareValueToKey方法可以对属性存在多个比较对象类型时自定义转换

This commit is contained in:
xuejiaming 2023-05-08 17:33:38 +08:00
parent dc5fb1a487
commit 9ae39a5a5c
4 changed files with 9 additions and 3 deletions

View File

@ -12,6 +12,7 @@ using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.Metadata;
using ShardingCore;
using ShardingCore.Core.VirtualRoutes.TableRoutes;
using ShardingCore.Extensions.ShardingQueryableExtensions;
using ShardingCore.Core;
@ -43,6 +44,7 @@ namespace Sample.SqlServer.Controllers
_shardingRouteManager = shardingRuntimeContext.GetShardingRouteManager();
_readWriteManager = shardingRuntimeContext.GetShardingReadWriteManager();
_shardingRuntimeContext = shardingRuntimeContext;
}
[HttpGet]

View File

@ -53,7 +53,7 @@ namespace ShardingCore.Core.VirtualRoutes.TableRoutes.Abstractions
{
if (EntityMetadata.IsMainShardingTableKey(shardingPropertyName))
{
return GetRouteToFilter((TKey)shardingKey, shardingOperator);
return GetRouteToFilter(CompareValueToKey(shardingKey), shardingOperator);
}
else
{
@ -61,6 +61,10 @@ namespace ShardingCore.Core.VirtualRoutes.TableRoutes.Abstractions
}
}
public virtual TKey CompareValueToKey(object shardingKey)
{
return (TKey)shardingKey;
}
public abstract Func<string, bool> GetRouteToFilter(TKey shardingKey,
ShardingOperatorEnum shardingOperator);

View File

@ -168,7 +168,7 @@ namespace ShardingCore.Sharding.Enumerators
if (aggregateValues.IsNotEmpty())
{
var copyFields = string.Join(",", _mergeContext.SelectContext.SelectProperties.Select(o=>o.PropertyName));
// var copyFields = string.Join(",", _mergeContext.SelectContext.SelectProperties.Select(o=>o.PropertyName));
CurrentValue = AggregateExtension.CopyTSource(aggregateValues.First());
if (aggregateValues.Count > 1)

View File

@ -75,7 +75,7 @@ namespace ShardingCore.Sharding.MergeEngines.Executors.ShardingMergers
//聚合
if (parallelResults is IEnumerable<IStreamMergeAsyncEnumerator<TEntity>> parallelStreamEnumeratorResults)
{
var mergeAsyncEnumerators = new List<IStreamMergeAsyncEnumerator<TEntity>>(parallelResults.Count);
var mergeAsyncEnumerators = new List<IStreamMergeAsyncEnumerator<TEntity>>(parallelResults.Count+previewResultsCount);
if (previewResultsCount == 1)
{
mergeAsyncEnumerators.Add(beforeInMemoryResults.First());