CountAll
This method counts all rows in a table.
Code Snippets
The following example counts all rows in the [dbo].[Person] table.
using (var connection = new SqlConnection(connectionString))
{
var counted = connection.CountAll<Person>();
}
Targeting a Table
To target a specific table, pass the literal table name.
using (var connection = new SqlConnection(connectionString))
{
var counted = connection.CountAll("[dbo].[Person]");
}
Table Hints
Pass a table hint via the hints argument.
using (var connection = new SqlConnection(connectionString))
{
var counted = connection.CountAll<Person>(hints: "WITH (NOLOCK)");
}
Or use the SqlServerTableHints class.
using (var connection = new SqlConnection(connectionString))
{
var counted = connection.CountAll<Person>(hints: SqlServerTableHints.NoLock);
}