withCount<TChild> method
MssqlProjectedQuery<(TRow, int)>
withCount<TChild>(
- MssqlRelation<
TRow, TChild> relation(- TFields fields
- bool big = true,
Parent rows plus a count of matching children, as a projection.
Not a field on the entity: a count is not a column of the table, and
stuffing it onto the row would make fromRow and equality lie.
Default is COUNT_BIG so a busy relation cannot overflow int
(error 8115). Pass big: false only when the count is known to fit
in 32 bits.
Implementation
MssqlProjectedQuery<(TRow, int)> withCount<TChild>(
MssqlRelation<TRow, TChild> Function(TFields fields) relation, {
bool big = true,
}) {
return _withAggregate(
relation,
big ? MssqlAggregate.countBig(raw('*')) : MssqlAggregate.count(raw('*')),
(value) => value == null ? 0 : (value as num).toInt(),
);
}