Show / Hide Table of Contents

    IDataStore.Count<TModel>(Predicate<TModel> predicate) Method

    .NET Standard 2.x

    Returns a number that represents how many rows in the primary buffer of DataStore satisfy a condition.

    Namespace: DWNet.Data

    Assembly: DWNet.Data.dll

    Syntax

      public int Count<TModel>(Predicate<TModel> predicate);
    

    Type Parameters

    TModel

    The type of a model class that matches with the current DataObject.

    Parameters

    predicate System.Predicate<TModel>

    A function to evaluate each row for a condition.

    Returns

    System.Int32

    A number that represents how many rows in the primary buffer of DataStore satisfy the condition in the predicate function.

    Examples

    The following code example demonstrates how to use the Count method to get the number of rows that meet the filter criteria.

    using Appeon.ApiDoc.Models;
    using DWNet.Data;
    using System;
    
    namespace Appeon.ApiDoc.IDataStoreExamples
    {
        public class CountExample
        {
            private readonly SchoolContext _context;
    
            public CountExample(SchoolContext dataContext)
            {
                // Sets the data context
                _context = dataContext;
            }
    
            public void Example()
            {
                // Instantiates a DataStore object with datawindow: d_department.
                var datastore = new DataStore("d_department", _context);
    
                datastore.Retrieve();
    
                // This datastore has four records
                Console.WriteLine("All Rowcount: {0}", datastore.RowCount);
    
                // This datastore has four records, but after filtering the records 
                // by 'Budget > 200000.00', the filtered rowcount becomes 2.
                int count = datastore.Count<D_Department>(a => a.Budget > 200000.00m);
    
                Console.WriteLine("The filtered Rowcount: {0}", count);
    
                /*This code produces the following output:
                
                All Rowcount: 4
                The filtered Rowcount: 2
                */
            }
        }
    }
    

    Example Refer To

    Model Class: D_Department
    DataWindow File: d_department

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon