public async Task<long> CountFilteredAsync(string filterName)
{
if (string.IsNullOrWhiteSpace(this.Database))
{
return 0;
}
if (!this.SkipValidation)
{
if (!this.Validated)
{
await this.ValidateAsync(AccessTypeEnum.Read, this.LoginId, this.Database, false).ConfigureAwait(false);
}
if (!this.HasAccess)
{
Log.Information(
$"Access to count entity \"{this.FullyQualifiedObjectName}\" was denied to the user with Login ID {this.LoginId}. Filter: {filterName}.");
throw new UnauthorizedException("Access is denied.");
}
}
var filters = await this.GetFiltersAsync(this.Database, filterName).ConfigureAwait(false);
var sql = new Sql($"SELECT COUNT(*) FROM {this.FullyQualifiedObjectName} WHERE deleted = @0", false);
FilterManager.AddFilters(ref sql, filters.ToList());
return await Factory.ScalarAsync<long>(this.Database, sql).ConfigureAwait(false);
}