Show / Hide Table of Contents

    IDataStore<TModel>.Filter(Predicate<TModel> predicate, bool removeFiltered = false) Method

    .NET Standard 2.x

    Filters rows based on the filter criteria specified by Predicate <TModel> and specifies whether rows that do not meet the filter criteria are moved to the filter buffer.

    Namespace: DWNet.Data

    Assembly: DWNet.Data.dll

    Syntax

    bool Filter(Predicate<TModel> predicate, bool removeFiltered = false);
    

    Parameters

    predicate Predicate<TModel>

    A Predicate<TModel> object that you want to use as the search criteria.

    removeFiltered System.Boolean

    When removeFiltered is set to true, the filtered data will not be saved in the filter buffer. The default is false.

    Returns

    System.Boolean

    Returns true if it succeeds.

    Examples

    The following code example demonstrates how to filter the department records using a Predicate<TModel> object.

    using Appeon.ApiDoc.Models;
    using DWNet.Data;
    using System;
    
    namespace Appeon.ApiDoc.IDataStore_GenericExamples
    {
        public class FilterExample
        {
            private readonly SchoolContext _context;
    
            public FilterExample(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();
    
                // There are 2 records in the Department table whose departmentid 
                // is less than 3.
                datastore.Filter(d => d.Departmentid < 3);
    
                Console.WriteLine("datastore.Count: {0}", datastore.Count);
                Console.WriteLine("datastore.FilteredCount: {0}", datastore.FilteredCount);
    
                // Clears data from all buffers
                datastore.Clear();
                datastore.Retrieve();
                // The filtered data will not be saved in the filter buffer.
                datastore.Filter(d => d.Departmentid < 3, true);
    
                Console.WriteLine("datastore.Count: {0}", datastore.Count);
                Console.WriteLine("datastore.FilteredCount: {0}", datastore.FilteredCount);
    
                /*This code produces the following output:
                 
                datastore.Count: 2
                datastore.FilteredCount: 2
    
                datastore.Count: 2
                datastore.FilteredCount: 0
                */
            }
        }
    }
    

    Example Refer To

    Model Class: D_Department
    DataWindow File: d_department

    Back to top Generated by Appeon