Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/Dommel/Count.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Data;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using Dapper;

Expand All @@ -19,7 +20,7 @@
{
var sql = BuildCountAllSql(GetSqlBuilder(connection), typeof(TEntity));
LogQuery<TEntity>(sql);
return connection.ExecuteScalar<long>(sql, transaction);
return connection.ExecuteScalar<long>(sql: sql, transaction: transaction);
}

/// <summary>
Expand All @@ -28,12 +29,13 @@
/// <typeparam name="TEntity">The type of the entity.</typeparam>
/// <param name="connection">The connection to the database. This can either be open or closed.</param>
/// <param name="transaction">Optional transaction for the command.</param>
/// <param name="cancellationToken">Optional cancellation token for the command.</param>
/// <returns>The number of entities matching the specified predicate.</returns>
public static Task<long> CountAsync<TEntity>(this IDbConnection connection, IDbTransaction? transaction = null)
public static Task<long> CountAsync<TEntity>(this IDbConnection connection, IDbTransaction? transaction = null, CancellationToken cancellationToken = default)

Check warning on line 34 in src/Dommel/Count.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

All 'CountAsync' method overloads should be adjacent.

See more on https://sonarcloud.io/project/issues?id=henkmollema_Dommel&issues=AZ3TlJ-2_JHI3XadXNJx&open=AZ3TlJ-2_JHI3XadXNJx&pullRequest=290
{
var sql = BuildCountAllSql(GetSqlBuilder(connection), typeof(TEntity));
LogQuery<TEntity>(sql);
return connection.ExecuteScalarAsync<long>(sql, transaction);
return connection.ExecuteScalarAsync<long>(new CommandDefinition(commandText: sql, transaction: transaction, cancellationToken: cancellationToken));
}

/// <summary>
Expand All @@ -58,12 +60,13 @@
/// <param name="connection">The connection to the database. This can either be open or closed.</param>
/// <param name="predicate">A predicate to filter the results.</param>
/// <param name="transaction">Optional transaction for the command.</param>
/// <param name="cancellationToken">Optional cancellation token for the command.</param>
/// <returns>The number of entities matching the specified predicate.</returns>
public static Task<long> CountAsync<TEntity>(this IDbConnection connection, Expression<Func<TEntity, bool>> predicate, IDbTransaction? transaction = null)
public static Task<long> CountAsync<TEntity>(this IDbConnection connection, Expression<Func<TEntity, bool>> predicate, IDbTransaction? transaction = null, CancellationToken cancellationToken = default)
{
var sql = BuildCountSql(GetSqlBuilder(connection), predicate, out var parameters);
LogQuery<TEntity>(sql);
return connection.ExecuteScalarAsync<long>(sql, parameters, transaction);
return connection.ExecuteScalarAsync<long>(new CommandDefinition(commandText: sql, parameters: parameters, transaction: transaction, cancellationToken: cancellationToken));
}

internal static string BuildCountAllSql(ISqlBuilder sqlBuilder, Type type)
Expand Down