Show / Hide Table of Contents

    ISqlModelMapper.Count<TModel>(params object[] parameters) Method

    .NET Standard 2.x

    Gets the number of rows in the result set retrieved, according to the criteria specified in a TModel class.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

      public int Count<TModel>(params object[] parameters);
    

    Type Parameters

    TModel

    The type of a model class.

    Parameters

    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.Int32

    Returns the number of rows in the database result set.

    Remarks

    This method uses the SQL COUNT() function internally.

    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 number of departments.

    using Appeon.ApiDoc.Models.School;
    using System;
    
    namespace Appeon.ApiDoc.ISqlModelMapperExamples
    {
        public class CountExample
        {
            private SchoolContext _context;
    
            public CountExample(SchoolContext dataContext)
            {
                // Sets the data context.
                _context = dataContext;
            }
    
            public void Example()
            {
                // Counts the number of departments.
                int count = _context.SqlModelMapper.Count<Department>();
    
                Console.WriteLine("The number of departments is {0}.",
                    count.ToString());
    
                /* The code produces the following output:
                
                The number of departments is 4.
                */
            }
        }
    }
    

    Example Refer To

    Model Class: Department

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon