mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 10:42:52 +08:00
- 增加 ISelectGrouping 分组查询总量的方法 .Count();
This commit is contained in:
parent
01c0fbf4f2
commit
f5128f3308
@ -722,6 +722,7 @@ namespace FreeSql.Tests.MySqlConnector
|
|||||||
.OrderByDescending(a => a.Count())
|
.OrderByDescending(a => a.Count())
|
||||||
.Offset(10)
|
.Offset(10)
|
||||||
.Limit(2)
|
.Limit(2)
|
||||||
|
.Count(out var trycount)
|
||||||
.ToList(a => new
|
.ToList(a => new
|
||||||
{
|
{
|
||||||
a.Key.tt2,
|
a.Key.tt2,
|
||||||
|
@ -648,6 +648,7 @@ namespace FreeSql.Tests.Odbc.Dameng
|
|||||||
.OrderByDescending(a => a.Count())
|
.OrderByDescending(a => a.Count())
|
||||||
.Offset(10)
|
.Offset(10)
|
||||||
.Limit(2)
|
.Limit(2)
|
||||||
|
.Count(out var trycount)
|
||||||
.ToList(a => new
|
.ToList(a => new
|
||||||
{
|
{
|
||||||
a.Key.tt2,
|
a.Key.tt2,
|
||||||
|
@ -639,6 +639,7 @@ namespace FreeSql.Tests.Odbc.Default
|
|||||||
.OrderBy(a => a.Key.tt2)
|
.OrderBy(a => a.Key.tt2)
|
||||||
.OrderByDescending(a => a.Count())
|
.OrderByDescending(a => a.Count())
|
||||||
.Limit(2)
|
.Limit(2)
|
||||||
|
.Count(out var trycount)
|
||||||
.ToList(a => new
|
.ToList(a => new
|
||||||
{
|
{
|
||||||
a.Key.tt2,
|
a.Key.tt2,
|
||||||
|
@ -732,6 +732,7 @@ namespace FreeSql.Tests.Odbc.MySql
|
|||||||
.OrderByDescending(a => a.Count())
|
.OrderByDescending(a => a.Count())
|
||||||
.Offset(10)
|
.Offset(10)
|
||||||
.Limit(2)
|
.Limit(2)
|
||||||
|
.Count(out var trycount)
|
||||||
.ToList(a => new
|
.ToList(a => new
|
||||||
{
|
{
|
||||||
a.Key.tt2,
|
a.Key.tt2,
|
||||||
|
@ -648,6 +648,7 @@ namespace FreeSql.Tests.Odbc.Oracle
|
|||||||
.OrderByDescending(a => a.Count())
|
.OrderByDescending(a => a.Count())
|
||||||
.Offset(10)
|
.Offset(10)
|
||||||
.Limit(2)
|
.Limit(2)
|
||||||
|
.Count(out var trycount)
|
||||||
.ToList(a => new
|
.ToList(a => new
|
||||||
{
|
{
|
||||||
a.Key.tt2,
|
a.Key.tt2,
|
||||||
|
@ -710,6 +710,7 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
|
|||||||
.OrderByDescending(a => a.Count())
|
.OrderByDescending(a => a.Count())
|
||||||
.Offset(10)
|
.Offset(10)
|
||||||
.Limit(2)
|
.Limit(2)
|
||||||
|
.Count(out var trycount)
|
||||||
.ToList(a => new
|
.ToList(a => new
|
||||||
{
|
{
|
||||||
a.Key.tt2,
|
a.Key.tt2,
|
||||||
|
@ -604,6 +604,7 @@ namespace FreeSql.Tests.Odbc.SqlServer
|
|||||||
.OrderByDescending(a => a.Count())
|
.OrderByDescending(a => a.Count())
|
||||||
.Offset(10)
|
.Offset(10)
|
||||||
.Limit(2)
|
.Limit(2)
|
||||||
|
.Count(out var trycount)
|
||||||
.ToList(a => new
|
.ToList(a => new
|
||||||
{
|
{
|
||||||
a.Key.tt2,
|
a.Key.tt2,
|
||||||
|
@ -763,6 +763,7 @@ namespace FreeSql.Tests.MySql
|
|||||||
.OrderByDescending(a => a.Count())
|
.OrderByDescending(a => a.Count())
|
||||||
.Offset(10)
|
.Offset(10)
|
||||||
.Limit(2)
|
.Limit(2)
|
||||||
|
.Count(out var trycount)
|
||||||
.ToList(a => new
|
.ToList(a => new
|
||||||
{
|
{
|
||||||
a.Key.tt2,
|
a.Key.tt2,
|
||||||
|
@ -648,6 +648,7 @@ namespace FreeSql.Tests.Oracle
|
|||||||
.OrderByDescending(a => a.Count())
|
.OrderByDescending(a => a.Count())
|
||||||
.Offset(10)
|
.Offset(10)
|
||||||
.Limit(2)
|
.Limit(2)
|
||||||
|
.Count(out var trycount)
|
||||||
.ToList(a => new
|
.ToList(a => new
|
||||||
{
|
{
|
||||||
a.Key.tt2,
|
a.Key.tt2,
|
||||||
|
@ -727,6 +727,7 @@ namespace FreeSql.Tests.PostgreSQL
|
|||||||
.OrderByDescending(a => a.Count())
|
.OrderByDescending(a => a.Count())
|
||||||
.Offset(10)
|
.Offset(10)
|
||||||
.Limit(2)
|
.Limit(2)
|
||||||
|
.Count(out var trycount)
|
||||||
.ToList(a => new
|
.ToList(a => new
|
||||||
{
|
{
|
||||||
a.Key.tt2,
|
a.Key.tt2,
|
||||||
|
@ -652,6 +652,7 @@ namespace FreeSql.Tests.SqlServer
|
|||||||
.OrderByDescending(a => a.Count())
|
.OrderByDescending(a => a.Count())
|
||||||
.Offset(10)
|
.Offset(10)
|
||||||
.Limit(2)
|
.Limit(2)
|
||||||
|
.Count(out var trycount)
|
||||||
.ToList(a => new
|
.ToList(a => new
|
||||||
{
|
{
|
||||||
a.Key.tt2,
|
a.Key.tt2,
|
||||||
|
@ -601,6 +601,7 @@ namespace FreeSql.Tests.Sqlite
|
|||||||
.OrderByDescending(a => a.Count())
|
.OrderByDescending(a => a.Count())
|
||||||
.Offset(10)
|
.Offset(10)
|
||||||
.Limit(2)
|
.Limit(2)
|
||||||
|
.Count(out var trycount)
|
||||||
.ToList(a => new
|
.ToList(a => new
|
||||||
{
|
{
|
||||||
a.Key.tt2,
|
a.Key.tt2,
|
||||||
|
@ -1776,6 +1776,19 @@
|
|||||||
<param name="pageSize">每页多少</param>
|
<param name="pageSize">每页多少</param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</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">
|
<member name="P:FreeSql.ISelectGroupingAggregate`1.Key">
|
||||||
<summary>
|
<summary>
|
||||||
分组的数据
|
分组的数据
|
||||||
|
@ -11,6 +11,7 @@ namespace FreeSql
|
|||||||
|
|
||||||
#if net40
|
#if net40
|
||||||
#else
|
#else
|
||||||
|
Task<long> CountAsync();
|
||||||
Task<List<TReturn>> ToListAsync<TReturn>(Expression<Func<ISelectGroupingAggregate<TKey, TValue>, TReturn>> select);
|
Task<List<TReturn>> ToListAsync<TReturn>(Expression<Func<ISelectGroupingAggregate<TKey, TValue>, TReturn>> select);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -95,6 +96,18 @@ namespace FreeSql
|
|||||||
/// <param name="pageSize">每页多少</param>
|
/// <param name="pageSize">每页多少</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
ISelectGrouping<TKey, TValue> Page(int pageNumber, int pageSize);
|
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>
|
public interface ISelectGroupingAggregate<TKey>
|
||||||
|
@ -1052,7 +1052,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
|
|
||||||
_commonExpression.ReadAnonymousField(_tables, field, map, ref index, columns, null, _whereCascadeExpression, true);
|
_commonExpression.ReadAnonymousField(_tables, field, map, ref index, columns, null, _whereCascadeExpression, true);
|
||||||
this.GroupBy(field.Length > 0 ? field.Remove(0, 2).ToString() : null);
|
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)
|
protected TSelect InternalJoin(Expression exp, SelectTableInfoType joinType)
|
||||||
{
|
{
|
||||||
|
@ -11,13 +11,14 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
{
|
{
|
||||||
public class SelectGroupingProvider<TKey, TValue> : ISelectGrouping<TKey, TValue>
|
public class SelectGroupingProvider<TKey, TValue> : ISelectGrouping<TKey, TValue>
|
||||||
{
|
{
|
||||||
|
internal IFreeSql _orm;
|
||||||
internal object _select;
|
internal object _select;
|
||||||
internal ReadAnonymousTypeInfo _map;
|
internal ReadAnonymousTypeInfo _map;
|
||||||
internal CommonExpression _comonExp;
|
internal CommonExpression _comonExp;
|
||||||
internal List<SelectTableInfo> _tables;
|
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;
|
_select = select;
|
||||||
_map = map;
|
_map = map;
|
||||||
_comonExp = comonExp;
|
_comonExp = comonExp;
|
||||||
@ -162,8 +163,17 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
return this;
|
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
|
#if net40
|
||||||
#else
|
#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)
|
public Task<List<TReturn>> ToListAsync<TReturn>(Expression<Func<ISelectGroupingAggregate<TKey, TValue>, TReturn>> select)
|
||||||
{
|
{
|
||||||
var map = new ReadAnonymousTypeInfo();
|
var map = new ReadAnonymousTypeInfo();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user