Show / Hide Table of Contents

    ISqlModelMapper.Min<TModel>(string expression, params object[] parameters) Method

    .NET Standard 2.x

    Gets the minimum 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 Min<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 minimum 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 minimum value of the retrieved data. Its data type is determined by the return value of the SQL expression.

    Remarks

    The expression parameter contains the SQL expression which will be used by the SQL MIN() 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 minimum budgets for departments.

    using Appeon.ApiDoc.Models.School;
    using System;
    
    namespace Appeon.ApiDoc.ISqlModelMapperExamples
    {
        public class MinExample
        {
            private SchoolContext _context;
    
            public MinExample(SchoolContext dataContext)
            {
                // Sets the data context.
                _context = dataContext;
            }
    
            public void Example()
            {
                // Calculates the minimum budget for departments.
                decimal MinBudget = (decimal)_context.SqlModelMapper
                                                     .Min<Department>("Budget");
    
                Console.WriteLine("The minimum budget is {0}.",
                    MinBudget.ToString("N0"));
    
                /* The code produces the following output:
                
                The minimum budget is 120,000.
                */
            }
        }
    }
    

    Example Refer To

    Model Class: Department

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon