ISqlModelMapper.Max<TModel>(string expression, params object[] parameters) Method
.NET Standard 2.x
Gets the maximum value for the specified SQL expression, according to the retrieval criteria specified in a TModel
class.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
public object Max<TModel>(string expression, params object[] parameters);
Type Parameters
TModel
The type of a model class.
Parameters
expression
System.String
A SQL expression string used to compute the maximum value.
parameters
System.Object[]
(Optional) One or more values that you want to use as retrieval arguments in the SQL SELECT statement defined in TModel
.
Returns
System.Object
The maximum value of the retrieved data. Its data type is determined by the return value of the SQL expression.
Remarks
The expression
parameter contains a SQL expression which will be used by the SQL MAX() function, therefore, the SQL expression string must comply with the SQL conventions, otherwise, exceptions may be thrown.
This method only returns the data of the first column in the first row of the retrieved data, therefore, please avoid using this method when groups are defined in TModel
.
Examples
The following code example demonstrates how to calculate the maximum budget for departments.
using Appeon.ApiDoc.Models.School;
using System;
namespace Appeon.ApiDoc.ISqlModelMapperExamples
{
public class MaxExample
{
private SchoolContext _context;
public MaxExample(SchoolContext dataContext)
{
// Sets the data context.
_context = dataContext;
}
public void Example()
{
// Calculates the maximum budget for departments.
decimal maxBudget = (decimal)_context.SqlModelMapper
.Max<Department>("Budget");
Console.WriteLine("The maximum budget is {0}.",
maxBudget.ToString("N0"));
/* The code produces the following output:
The maximum budget is 350,000.
*/
}
}
}
Example Refer To
Model Class: Department
Applies to
.NET Standard
2.x