DapperLib / Dapper.Contrib

Dapper community contributions - additional extensions for Dapper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

palenshus opened this issue · comments

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