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

Open
#138 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
45/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
csharp
Domain
database

Research direction

Start by reading the existing Get and GetAll implementations and how TableAttribute is handled. Add a Count() extension on IDbConnection that uses the mapped table name and returns the row count; done means the method is exposed consistently with the other extensions.

Written by the indexing model from the issue text.

Description

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

Dominant language
C#
Stars
293
Forks
109
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from DapperLib/Dapper.Contrib

All issues in DapperLib/Dapper.Contrib

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.