mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 12:28:15 +08:00
- 增加 ISelectGrouping 分组查询总量的方法 .Count();
This commit is contained in:
@ -1776,6 +1776,19 @@
|
||||
<param name="pageSize">每页多少</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.ISelectGrouping`2.Count">
|
||||
<summary>
|
||||
查询的记录数量
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.ISelectGrouping`2.Count(System.Int64@)">
|
||||
<summary>
|
||||
查询的记录数量,以参数out形式返回
|
||||
</summary>
|
||||
<param name="count">返回的变量</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="P:FreeSql.ISelectGroupingAggregate`1.Key">
|
||||
<summary>
|
||||
分组的数据
|
||||
|
@ -11,6 +11,7 @@ namespace FreeSql
|
||||
|
||||
#if net40
|
||||
#else
|
||||
Task<long> CountAsync();
|
||||
Task<List<TReturn>> ToListAsync<TReturn>(Expression<Func<ISelectGroupingAggregate<TKey, TValue>, TReturn>> select);
|
||||
#endif
|
||||
|
||||
@ -95,6 +96,18 @@ namespace FreeSql
|
||||
/// <param name="pageSize">每页多少</param>
|
||||
/// <returns></returns>
|
||||
ISelectGrouping<TKey, TValue> Page(int pageNumber, int pageSize);
|
||||
|
||||
/// <summary>
|
||||
/// 查询的记录数量
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
long Count();
|
||||
/// <summary>
|
||||
/// 查询的记录数量,以参数out形式返回
|
||||
/// </summary>
|
||||
/// <param name="count">返回的变量</param>
|
||||
/// <returns></returns>
|
||||
ISelectGrouping<TKey, TValue> Count(out long count);
|
||||
}
|
||||
|
||||
public interface ISelectGroupingAggregate<TKey>
|
||||
|
@ -1052,7 +1052,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
|
||||
_commonExpression.ReadAnonymousField(_tables, field, map, ref index, columns, null, _whereCascadeExpression, true);
|
||||
this.GroupBy(field.Length > 0 ? field.Remove(0, 2).ToString() : null);
|
||||
return new SelectGroupingProvider<TKey, TValue>(this, map, _commonExpression, _tables);
|
||||
return new SelectGroupingProvider<TKey, TValue>(_orm, this, map, _commonExpression, _tables);
|
||||
}
|
||||
protected TSelect InternalJoin(Expression exp, SelectTableInfoType joinType)
|
||||
{
|
||||
|
@ -11,13 +11,14 @@ namespace FreeSql.Internal.CommonProvider
|
||||
{
|
||||
public class SelectGroupingProvider<TKey, TValue> : ISelectGrouping<TKey, TValue>
|
||||
{
|
||||
|
||||
internal IFreeSql _orm;
|
||||
internal object _select;
|
||||
internal ReadAnonymousTypeInfo _map;
|
||||
internal CommonExpression _comonExp;
|
||||
internal List<SelectTableInfo> _tables;
|
||||
public SelectGroupingProvider(object select, ReadAnonymousTypeInfo map, CommonExpression comonExp, List<SelectTableInfo> tables)
|
||||
public SelectGroupingProvider(IFreeSql orm, object select, ReadAnonymousTypeInfo map, CommonExpression comonExp, List<SelectTableInfo> tables)
|
||||
{
|
||||
_orm = orm;
|
||||
_select = select;
|
||||
_map = map;
|
||||
_comonExp = comonExp;
|
||||
@ -162,8 +163,17 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return this;
|
||||
}
|
||||
|
||||
public long Count() => long.TryParse(string.Concat(_orm.Ado.ExecuteScalar($"select count(1) from ({this.ToSql("1 as1")}) fta")), out var trylng) ? trylng : default(long);
|
||||
public ISelectGrouping<TKey, TValue> Count(out long count)
|
||||
{
|
||||
count = this.Count();
|
||||
return this;
|
||||
}
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public Task<long> CountAsync() => long.TryParse(string.Concat(await _orm.Ado.ExecuteScalarAsync($"select count(1) from ({this.ToSql("1 as1")}) fta")), out var trylng) ? trylng : default(long);
|
||||
|
||||
public Task<List<TReturn>> ToListAsync<TReturn>(Expression<Func<ISelectGroupingAggregate<TKey, TValue>, TReturn>> select)
|
||||
{
|
||||
var map = new ReadAnonymousTypeInfo();
|
||||
|
Reference in New Issue
Block a user