This commit is contained in:
2881099
2021-04-19 04:32:27 +08:00
23 changed files with 584 additions and 4 deletions

View File

@ -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()));
}
}

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