Count entities
there are a couple of ways to get the count of entities stored in a collection.
Count estimated total
var count = await DB.CountEstimatedAsync<Author>();
you can get a fast estimate of total entities for a given entity type at the expense of accuracy. the above will give you a rough estimate of the total entities using collection meta-data.
Count total entities
var count = await DB.CountAsync<Author>();
the above will give you an accurate count of total entities by running an aggregation query.
Count matches with an expression
var count = await DB.CountAsync<Author>(a => a.Title == "The Power Of Now");
Count matches with a filter builder function
var count = await DB.CountAsync<Author>(b => b.Eq(a => a.Name, "Eckhart Tolle"));
Count matches with a filter definition
var filter = DB.Filter<Author>()
.Eq(a => a.Name, "Eckhart Tolle");
var count = await DB.CountAsync(filter);
Counting children of a relationship
you can get how many entities are there in the opposite side of any relationship as shown below:
var authorCount = await book.Authors.ChildrenCountAsync();
var bookCount = await author.Books.ChildrenCountAsync();