Following section demonstrates using Count extension, to get count of row(s).
// Table Aliases
var t0 = new Orders().AsQueryable();
// Query
var query = Odb.SQL.Select(x => x.From(t0));
// Read
var result = cn.{{hl}}Count(query){{/hl}};
dRfL97
Limitations of Count extension.
-
All selection fields are ignored and only value of the COUNT() is returned.
-
All rows are counted regardless the field values.
-
Order clause is ingored, because it is not necessary.
To counting the field values by excluding NULL values, you have to use COUNT with a column.
// Table Aliases
var t0 = new Orders().AsQueryable();
using(var exc = cn.Executer()) {
var query = Odb.SQL.Select(x => x.From(t0).Fields( {{hl}}x[t0.OrderID].COUNT(){{/hl}} ));
var result = (int?)(cn.Sql(query).Read().FirstOrDefault()?[0]) ?? 0;
}
dRfL97