class GroupByTableCursor<TTable>
where TTable : ITable;
4. ToCursor
4.1 ToCursor扩展方法
从sql分组创建分组游标
GroupByTableCursor<TTable> ToCursor<TTable>(this GroupByTableSqlQuery<TTable> groupBy, int limit = 0, int offset = 0)
where TTable : ITable;
var cursor = _db.From("Employees")
.SqlGroupBy("DepartmentId")
.ToCursor();
.CountAsc();
// SELECT * FROM [Employees] GROUP BY [DepartmentId] ORDER BY COUNT(*)
4.2 ToCursor重载扩展方法
从逻辑分组创建分组游标
GroupByTableCursor<TTable> ToCursor<TTable>(this GroupByTableQuery<TTable> groupBy, int limit = 0, int offset = 0)
where TTable : ITable;
var cursor = _db.From("Employees")
.GroupBy("DepartmentId")
.ToCursor()
.AggregateDesc(g => g.Max("Age"));
// SELECT * FROM [Employees] GROUP BY [DepartmentId] ORDER BY MAX([Age]) DESC
var cursor = new CommentTable()
.SqlGroupBy(c => [c.PostId])
.ToCursor()
.AggregateAsc(c => c.Pick.Sum());
// SELECT * FROM [Comments] GROUP BY [PostId] ORDER BY SUM([Pick])
var cursor = new CommentTable()
.GroupBy(c => [c.PostId])
.ToCursor()
.AggregateDesc(c => c.Pick.Sum());
// SELECT * FROM [Comments] GROUP BY [PostId] ORDER BY SUM([Pick]) DESC