diff --git a/src/ShardingCore/Sharding/PaginationConfigurations/IPaginationConfiguration.cs b/src/ShardingCore/Sharding/PaginationConfigurations/IPaginationConfiguration.cs index 81cde904..44f6f56a 100644 --- a/src/ShardingCore/Sharding/PaginationConfigurations/IPaginationConfiguration.cs +++ b/src/ShardingCore/Sharding/PaginationConfigurations/IPaginationConfiguration.cs @@ -14,10 +14,6 @@ namespace ShardingCore.Sharding.PaginationConfigurations */ public interface IPaginationConfiguration where TEntity : class,IShardingTable { - /// - /// Configures the entity of type . - /// - /// The builder to be used to configure the entity type. - void Configure(Paginati onBuilder builder); + void Configure(PaginationBuilder builder); } } diff --git a/src/ShardingCore/Sharding/PaginationConfigurations/PaginationBuilder.cs b/src/ShardingCore/Sharding/PaginationConfigurations/PaginationBuilder.cs index ed09ca1b..5cdea843 100644 --- a/src/ShardingCore/Sharding/PaginationConfigurations/PaginationBuilder.cs +++ b/src/ShardingCore/Sharding/PaginationConfigurations/PaginationBuilder.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; +using System.Linq.Expressions; using System.Text; +using Microsoft.EntityFrameworkCore.Infrastructure; using ShardingCore.Core; namespace ShardingCore.Sharding.PaginationConfigurations @@ -14,5 +16,14 @@ namespace ShardingCore.Sharding.PaginationConfigurations */ public class PaginationBuilder where TEntity:class,IShardingTable { + /// + /// 分页顺序 + /// + /// + /// + public PaginationOrderPropertyBuilder PaginationSequence(Expression> orderPropertyExpression) + { + return new PaginationOrderPropertyBuilder(orderPropertyExpression); + } } } diff --git a/src/ShardingCore/Sharding/PaginationConfigurations/PaginationMatchEnum.cs b/src/ShardingCore/Sharding/PaginationConfigurations/PaginationMatchEnum.cs new file mode 100644 index 00000000..ae67748f --- /dev/null +++ b/src/ShardingCore/Sharding/PaginationConfigurations/PaginationMatchEnum.cs @@ -0,0 +1,16 @@ +using System; + +namespace ShardingCore.Sharding.PaginationConfigurations +{ +/* +* @Author: xjm +* @Description: +* @Date: Wednesday, 01 September 2021 21:27:25 +* @Email: 326308290@qq.com +*/ + public enum PaginationMatchEnum + { + Owner=1, + Named=1<<1 + } +} \ No newline at end of file diff --git a/src/ShardingCore/Sharding/PaginationConfigurations/PaginationOrderPropertyBuilder.cs b/src/ShardingCore/Sharding/PaginationConfigurations/PaginationOrderPropertyBuilder.cs new file mode 100644 index 00000000..050ae25b --- /dev/null +++ b/src/ShardingCore/Sharding/PaginationConfigurations/PaginationOrderPropertyBuilder.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Infrastructure; + +namespace ShardingCore.Sharding.PaginationConfigurations +{ +/* +* @Author: xjm +* @Description: +* @Date: Wednesday, 01 September 2021 21:32:53 +* @Email: 326308290@qq.com +*/ + public class PaginationOrderPropertyBuilder + { + private readonly LambdaExpression _orderPropertyExpression; + private IComparer _tailComparer; + private PaginationMatchEnum _paginationMatchEnum; + private PropertyInfo _orderPropertyInfo; + + public PaginationOrderPropertyBuilder(LambdaExpression orderPropertyExpression) + { + _orderPropertyExpression = orderPropertyExpression; + _orderPropertyInfo = orderPropertyExpression.GetPropertyAccess(); + } + + /// + /// 使用哪个后缀比较 + /// + /// + /// + public PaginationOrderPropertyBuilder UseTailCompare(IComparer tailComparer) + { + _tailComparer = tailComparer ?? throw new ArgumentException(nameof(tailComparer)); + return this; + } + /// + /// 使用哪种比较方式 + /// + /// + /// + public PaginationOrderPropertyBuilder UseQueryMatch(PaginationMatchEnum paginationMatchEnum) + { + _paginationMatchEnum = paginationMatchEnum; + return this; + } + } +} \ No newline at end of file diff --git a/src/ShardingCore/Sharding/StreamMergeEngines/LongCountAsyncInMemoryMergeEngine.cs b/src/ShardingCore/Sharding/StreamMergeEngines/LongCountAsyncInMemoryMergeEngine.cs index f6c1f5a0..15b2b9b1 100644 --- a/src/ShardingCore/Sharding/StreamMergeEngines/LongCountAsyncInMemoryMergeEngine.cs +++ b/src/ShardingCore/Sharding/StreamMergeEngines/LongCountAsyncInMemoryMergeEngine.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using ShardingCore.Exceptions; +using ShardingCore.Helpers; using ShardingCore.Sharding.Abstractions; using ShardingCore.Sharding.Enumerators; using ShardingCore.Sharding.StreamMergeEngines.Abstractions; @@ -30,10 +31,7 @@ namespace ShardingCore.Sharding.StreamMergeEngines public override long MergeResult() { - - var result = base.Execute( queryable => ((IQueryable)queryable).LongCount()); - - return result.Sum(); + return AsyncHelper.RunSync(() => MergeResultAsync()); } public override async Task MergeResultAsync(CancellationToken cancellationToken = new CancellationToken()) @@ -41,7 +39,7 @@ namespace ShardingCore.Sharding.StreamMergeEngines var result = await base.ExecuteAsync( queryable => ((IQueryable)queryable).LongCountAsync(cancellationToken), cancellationToken); - return result.Sum(); + return result.Sum(o=>o.QueryResult); } } } \ No newline at end of file