DapperLib / Dapper.Contrib

Dapper community contributions - additional extensions for Dapper
Other
268 stars 99 forks source link

Dapper should expose a .Count<T>() method #138

Open palenshus opened 2 years ago

palenshus commented 2 years ago

The implementation should be quite simple I believe, similar to how Get or GetAll are implemented. Here's the extension method I've been using:

public static int Count<T>(this IDbConnection connection)
{
    return connection.QuerySingle<int>($"SELECT COUNT(1) FROM {typeof(T).Name}");
}

Obviously the real implementation would need to incorporate the TableAttribute