Link Search Menu Expand Document

MinAll


This method computes the minimum value of the target field across all rows.

Code Snippets

The following example returns the minimum value of the Value column from the [dbo].[Sales] table.

using (var connection = new SqlConnection(connectionString))
{
    var expenses = connection.MinAll<Sales>(e => e.Value);
}

Targeting a Table

To target a specific table, pass the literal table and field name.

using (var connection = new SqlConnection(connectionString))
{
    var expenses = connection.MinAll("[dbo].[Sales]",
        Field.From("Value"));
}

Table Hints

Pass a table hint via the hints argument.

using (var connection = new SqlConnection(connectionString))
{
    var expenses = connection.MinAll<Sales>(e => e.Value,
        hints: "WITH (NOLOCK)");
}

Or use the SqlServerTableHints class.

using (var connection = new SqlConnection(connectionString))
{
    var expenses = connection.MinAll<Sales>(e => e.Value,
        hints: SqlServerTableHints.NoLock);
}