diff --git a/Examples/repository_01/Controllers/SongController.cs b/Examples/repository_01/Controllers/SongController.cs
index 4381d575..a6bb50de 100644
--- a/Examples/repository_01/Controllers/SongController.cs
+++ b/Examples/repository_01/Controllers/SongController.cs
@@ -63,6 +63,17 @@ namespace restful.Controllers
return _songRepository.Select.WhereIf(!string.IsNullOrEmpty(key), a => a.Title.Contains(key)).Page(page, limit).ToListAsync();
}
+ ///
+ /// curl -X GET "http://localhost:5000/restapi/Songs/GetPagingItems?key=FreeSql&PageNumber=2&PageSize=10" -H "accept: text/plain"
+ ///
+ ///
+ ///
+ [HttpGet("GetPagingItems")]
+ public Task> GetPagingItems([FromQuery] string key, [FromQuery] PagingInfo pagingInfo)
+ {
+ return _songRepository.Select.WhereIf(!string.IsNullOrEmpty(key), a => a.Title.Contains(key)).Page(pagingInfo).ToListAsync();
+ }
+
[HttpGet("{id}")]
public Task GetItem([FromRoute] int id)
{
diff --git a/Examples/repository_01/PagingInfo.cs b/Examples/repository_01/PagingInfo.cs
new file mode 100644
index 00000000..803ec20c
--- /dev/null
+++ b/Examples/repository_01/PagingInfo.cs
@@ -0,0 +1,57 @@
+using FreeSql.Internal.Model;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace repository_01
+{
+ public class PagingInfo : BasePagingInfo
+ {
+ ///
+ /// 无参构造函数
+ ///
+ public PagingInfo()
+ {
+ }
+ ///
+ /// 当前为第1页,每页大小的构造函数
+ ///
+ ///
+ public PagingInfo(int pageSize)
+ {
+ PageNumber = 1;
+ PageSize = pageSize;
+ }
+ ///
+ /// 带当前页和每页大小的构造函数
+ ///
+ ///
+ ///
+ public PagingInfo(int pageNumber, int pageSize)
+ {
+ PageNumber = pageNumber;
+ PageSize = pageSize;
+ }
+ ///
+ /// 当前有多少页【只读】
+ ///
+ public long PageCount => PageSize == 0 ? 0 : (Count + PageSize - 1) / PageSize;
+ ///
+ /// 是否有上一页【只读】
+ ///
+ public bool HasPrevious => PageNumber > 1 && PageNumber <= PageCount;
+ ///
+ /// 是否有下一页【只读】
+ ///
+ public bool HasNext => PageNumber < PageCount;
+ ///
+ /// 是否在第一页【只读】
+ ///
+ public bool IsFrist => PageNumber == 1;
+ ///
+ /// 是否在最后一页【只读】
+ ///
+ public bool IsLast => PageNumber == PageCount;
+ }
+}
\ No newline at end of file
diff --git a/Examples/restful/Controllers/SongController.cs b/Examples/restful/Controllers/SongController.cs
index 0cd631ae..98980779 100644
--- a/Examples/restful/Controllers/SongController.cs
+++ b/Examples/restful/Controllers/SongController.cs
@@ -25,6 +25,18 @@ namespace restful.Controllers
return _fsql.Select().WhereIf(!string.IsNullOrEmpty(key), a => a.Title.Contains(key)).Page(page, limit).ToListAsync();
}
+ ///
+ /// curl -X GET "http://localhost:5000/restapi/Songs/GetPagingItems?key=FreeSql&PageNumber=2&PageSize=10" -H "accept: text/plain"
+ ///
+ ///
+ ///
+ ///
+ [HttpGet("GetPagingItems")]
+ public Task> GetPagingItems([FromQuery] string key, [FromQuery] PagingInfo pagingInfo)
+ {
+ return _fsql.Select().WhereIf(!string.IsNullOrEmpty(key), a => a.Title.Contains(key)).Page(pagingInfo).ToListAsync();
+ }
+
[HttpGet("{id}")]
public Task GetItem([FromRoute] int id)
{
diff --git a/Examples/restful/PagingInfo.cs b/Examples/restful/PagingInfo.cs
new file mode 100644
index 00000000..ab52c180
--- /dev/null
+++ b/Examples/restful/PagingInfo.cs
@@ -0,0 +1,57 @@
+using FreeSql.Internal.Model;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace restful
+{
+ public class PagingInfo : BasePagingInfo
+ {
+ ///
+ /// 无参构造函数
+ ///
+ public PagingInfo()
+ {
+ }
+ ///
+ /// 当前为第1页,每页大小的构造函数
+ ///
+ ///
+ public PagingInfo(int pageSize)
+ {
+ PageNumber = 1;
+ PageSize = pageSize;
+ }
+ ///
+ /// 带当前页和每页大小的构造函数
+ ///
+ ///
+ ///
+ public PagingInfo(int pageNumber, int pageSize)
+ {
+ PageNumber = pageNumber;
+ PageSize = pageSize;
+ }
+ ///
+ /// 当前有多少页【只读】
+ ///
+ public long PageCount => PageSize == 0 ? 0 : (Count + PageSize - 1) / PageSize;
+ ///
+ /// 是否有上一页【只读】
+ ///
+ public bool HasPrevious => PageNumber > 1 && PageNumber <= PageCount;
+ ///
+ /// 是否有下一页【只读】
+ ///
+ public bool HasNext => PageNumber < PageCount;
+ ///
+ /// 是否在第一页【只读】
+ ///
+ public bool IsFrist => PageNumber == 1;
+ ///
+ /// 是否在最后一页【只读】
+ ///
+ public bool IsLast => PageNumber == PageCount;
+ }
+}
\ No newline at end of file
diff --git a/FreeSql/FreeSql.xml b/FreeSql/FreeSql.xml
index ad59871a..892888fe 100644
--- a/FreeSql/FreeSql.xml
+++ b/FreeSql/FreeSql.xml
@@ -2136,6 +2136,13 @@
每页多少
+
+
+ 分页
+
+ 分页信息
+
+
查询数据前,去重
@@ -2607,6 +2614,13 @@
每页多少
+
+
+ 分页
+
+ 分页信息
+
+
查询的记录数量
@@ -3976,6 +3990,26 @@
+
+
+ 分页信息
+
+
+
+
+ 第几页,从1开始
+
+
+
+
+ 每页多少
+
+
+
+
+ 查询的记录数量
+
+
当前操作的数据
diff --git a/FreeSql/Interface/Curd/ISelect/ISelect0.cs b/FreeSql/Interface/Curd/ISelect/ISelect0.cs
index 1ecab564..d17490da 100644
--- a/FreeSql/Interface/Curd/ISelect/ISelect0.cs
+++ b/FreeSql/Interface/Curd/ISelect/ISelect0.cs
@@ -402,6 +402,13 @@ namespace FreeSql
///
TSelect Page(int pageNumber, int pageSize);
+ ///
+ /// 分页
+ ///
+ /// 分页信息
+ ///
+ TSelect Page(BasePagingInfo pagingInfo);
+
///
/// 查询数据前,去重
///
diff --git a/FreeSql/Interface/Curd/ISelect/ISelectGrouping.cs b/FreeSql/Interface/Curd/ISelect/ISelectGrouping.cs
index 295b7411..c787cc61 100644
--- a/FreeSql/Interface/Curd/ISelect/ISelectGrouping.cs
+++ b/FreeSql/Interface/Curd/ISelect/ISelectGrouping.cs
@@ -1,4 +1,5 @@
-using System;
+using FreeSql.Internal.Model;
+using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;
@@ -101,6 +102,13 @@ namespace FreeSql
///
ISelectGrouping Page(int pageNumber, int pageSize);
+ ///
+ /// 分页
+ ///
+ /// 分页信息
+ ///
+ ISelectGrouping Page(BasePagingInfo pagingInfo);
+
///
/// 查询的记录数量
///
diff --git a/FreeSql/Internal/CommonProvider/InsertProvider.cs b/FreeSql/Internal/CommonProvider/InsertProvider.cs
index 1a1378b7..5a2b62cb 100644
--- a/FreeSql/Internal/CommonProvider/InsertProvider.cs
+++ b/FreeSql/Internal/CommonProvider/InsertProvider.cs
@@ -179,7 +179,7 @@ namespace FreeSql.Internal.CommonProvider
}
if (val == null && col.Attribute.MapType == typeof(string) && col.Attribute.IsNullable == false)
col.SetValue(data, val = "");
- if (val == null && col.Attribute.MapType == typeof(byte[]) && col.Attribute.IsVersion)
+ if (col.Attribute.MapType == typeof(byte[]) && (val == null || (val is byte[] bytes && bytes.Length == 0)) && col.Attribute.IsVersion)
col.SetValue(data, val = Utils.GuidToBytes(Guid.NewGuid()));
}
}
diff --git a/FreeSql/Internal/CommonProvider/SelectProvider/Select0Provider.cs b/FreeSql/Internal/CommonProvider/SelectProvider/Select0Provider.cs
index 74cfd9f3..d82980eb 100644
--- a/FreeSql/Internal/CommonProvider/SelectProvider/Select0Provider.cs
+++ b/FreeSql/Internal/CommonProvider/SelectProvider/Select0Provider.cs
@@ -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;
diff --git a/FreeSql/Internal/CommonProvider/SelectProvider/SelectGroupingProvider.cs b/FreeSql/Internal/CommonProvider/SelectProvider/SelectGroupingProvider.cs
index 09c524e0..68ca4c50 100644
--- a/FreeSql/Internal/CommonProvider/SelectProvider/SelectGroupingProvider.cs
+++ b/FreeSql/Internal/CommonProvider/SelectProvider/SelectGroupingProvider.cs
@@ -201,6 +201,14 @@ namespace FreeSql.Internal.CommonProvider
return this;
}
+ public ISelectGrouping 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 Count(out long count)
{
diff --git a/FreeSql/Internal/Model/BasePagingInfo.cs b/FreeSql/Internal/Model/BasePagingInfo.cs
new file mode 100644
index 00000000..2a48e529
--- /dev/null
+++ b/FreeSql/Internal/Model/BasePagingInfo.cs
@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace FreeSql.Internal.Model
+{
+ ///
+ /// 分页信息
+ ///
+ public class BasePagingInfo
+ {
+ ///
+ /// 第几页,从1开始
+ ///
+ public int PageNumber { get; set; }
+ ///
+ /// 每页多少
+ ///
+ public int PageSize { get; set; }
+ ///
+ /// 查询的记录数量
+ ///
+ public long Count { get; set; }
+ }
+}
\ No newline at end of file