This commit is contained in:
xuejmnet 2021-09-01 21:44:31 +08:00
parent af71145aee
commit 631115a317
5 changed files with 80 additions and 10 deletions

View File

@ -14,10 +14,6 @@ namespace ShardingCore.Sharding.PaginationConfigurations
*/
public interface IPaginationConfiguration<TEntity> where TEntity : class,IShardingTable
{
/// <summary>
/// Configures the entity of type <typeparamref name="TEntity" />.
/// </summary>
/// <param name="builder"> The builder to be used to configure the entity type. </param>
void Configure(Paginati onBuilder<TEntity> builder);
void Configure(PaginationBuilder<TEntity> builder);
}
}

View File

@ -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<TEntity> where TEntity:class,IShardingTable
{
/// <summary>
/// 分页顺序
/// </summary>
/// <param name="orderPropertyExpression"></param>
/// <typeparam name="TProperty"></typeparam>
public PaginationOrderPropertyBuilder PaginationSequence<TProperty>(Expression<Func<TEntity, TProperty>> orderPropertyExpression)
{
return new PaginationOrderPropertyBuilder(orderPropertyExpression);
}
}
}

View File

@ -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
}
}

View File

@ -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<string> _tailComparer;
private PaginationMatchEnum _paginationMatchEnum;
private PropertyInfo _orderPropertyInfo;
public PaginationOrderPropertyBuilder(LambdaExpression orderPropertyExpression)
{
_orderPropertyExpression = orderPropertyExpression;
_orderPropertyInfo = orderPropertyExpression.GetPropertyAccess();
}
/// <summary>
/// 使用哪个后缀比较
/// </summary>
/// <param name="tailComparer"></param>
/// <returns></returns>
public PaginationOrderPropertyBuilder UseTailCompare(IComparer<string> tailComparer)
{
_tailComparer = tailComparer ?? throw new ArgumentException(nameof(tailComparer));
return this;
}
/// <summary>
/// 使用哪种比较方式
/// </summary>
/// <param name="paginationMatchEnum"></param>
/// <returns></returns>
public PaginationOrderPropertyBuilder UseQueryMatch(PaginationMatchEnum paginationMatchEnum)
{
_paginationMatchEnum = paginationMatchEnum;
return this;
}
}
}

View File

@ -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<TEntity>)queryable).LongCount());
return result.Sum();
return AsyncHelper.RunSync(() => MergeResultAsync());
}
public override async Task<long> MergeResultAsync(CancellationToken cancellationToken = new CancellationToken())
@ -41,7 +39,7 @@ namespace ShardingCore.Sharding.StreamMergeEngines
var result = await base.ExecuteAsync( queryable => ((IQueryable<TEntity>)queryable).LongCountAsync(cancellationToken), cancellationToken);
return result.Sum();
return result.Sum(o=>o.QueryResult);
}
}
}