Merge pull request #729 from KaneLeung/master

🚀增加分页模型分页及示例
This commit is contained in:
Eternity
2021-04-06 19:13:18 +08:00
committed by GitHub
10 changed files with 227 additions and 1 deletions

View File

@ -319,6 +319,13 @@ namespace FreeSql.Internal.CommonProvider
return this.Limit(pageSize) as TSelect;
}
public TSelect Page(BasePagingInfo pagingInfo)
{
pagingInfo.Count = this.Count();
this.Skip(Math.Max(0, pagingInfo.PageNumber - 1) * pagingInfo.PageSize);
return this.Limit(pagingInfo.PageSize) as TSelect;
}
public TSelect Skip(int offset)
{
_skip = offset;

View File

@ -201,6 +201,14 @@ namespace FreeSql.Internal.CommonProvider
return this;
}
public ISelectGrouping<TKey, TValue> Page(BasePagingInfo pagingInfo)
{
pagingInfo.Count = this.Count();
_groupBySkip = Math.Max(0, pagingInfo.PageNumber - 1) * pagingInfo.PageSize;
_groupByLimit = pagingInfo.PageSize;
return this;
}
public long Count() => _select._cancel?.Invoke() == true ? 0 : long.TryParse(string.Concat(_orm.Ado.ExecuteScalar(_select._connection, _select._transaction, CommandType.Text, $"select count(1) from ({this.ToSql($"1{_comonExp._common.FieldAsAlias("as1")}")}) fta", _select._commandTimeout, _select._params.ToArray())), out var trylng) ? trylng : default(long);
public ISelectGrouping<TKey, TValue> Count(out long count)
{

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace FreeSql.Internal.Model
{
/// <summary>
/// 分页信息
/// </summary>
public class BasePagingInfo
{
/// <summary>
/// 第几页从1开始
/// </summary>
public int PageNumber { get; set; }
/// <summary>
/// 每页多少
/// </summary>
public int PageSize { get; set; }
/// <summary>
/// 查询的记录数量
/// </summary>
public long Count { get; set; }
}
}