Show / Hide Table of Contents

    ISqlModelMapper.LoadAllByPageAsync<TModel>(int currentIndex, int pageSize) Method

    .NET Standard 2.x

    Asynchronously retrieves data starting from a specified row according to the SQL query (without the Where clause) defined by the primary table in a TModel class.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

    public Task<ILoadable<TModel>> LoadAllByPageAsync<TModel>(int currentIndex, int pageSize)
    

    Type Parameters

    TModel

    The type of a model class.

    Parameters

    currentIndex System.Int32

    The zero-based index number of the first row.

    pageSize System.Int32

    The number of rows per page.

    Returns

    Task<ILoadable<TModel>>

    Returns a task that represents the asynchronous operation.

    Remarks

    If the SQL query defined in TModel makes query from multiple tables, then this method only retrieves and loads data from the primary table.

    Examples

    The following code example demonstrates how to asynchronously load the specified page according to the SQL query (without the Where clause) defined by the DepartmentByName class.

    using System;
    using System.Collections.Generic;
    using System.Threading;
    using System.Threading.Tasks;
    using Appeon.ApiDoc.Models.School;
    
    namespace Appeon.ApiDoc.ISqlModelMapperExamples
    {
        public class LoadAllByPageAsyncExample
        {
            private readonly SchoolContext _context;
            
            public LoadAllByPageAsyncExample(SchoolContext dataContext)
            {
                // Sets the data context.
                _context = dataContext;
            }
    
            public async Task<int> Example1()
            {
                var mapper = _context.SqlModelMapper;
                
                // Asynchronously loads the department of Engineering using LoadAll.
                // It retrieves all records from Department table. 
                var depts = (await mapper.LoadAllAsync<DepartmentByName>()).ToList();
                
                Console.WriteLine("All departments:");
                foreach (var department in depts)
                {
                    Console.WriteLine(department.Name);
                }
                
                Console.WriteLine();
                
                // Asynchronously loads the first page only (2 records per page)
                var deptsPage1 = (await mapper.LoadAllByPageAsync<DepartmentByName>(0, 2)).ToList();
                
                Console.WriteLine("Departments (Page 1):");
                foreach (var department in deptsPage1)
                {
                    Console.WriteLine(department.Name);
                }
                
                return deptsPage1.Count;
                
                /* The code produces the following output:
                
                    All departments:
                    Engineering
                    English
                    Economics
                    Mathematics
                    
                    Departments (Page 1):
                    Engineering
                    English
                */
            }
        }
    }
    

    Example Refer To

    Model Class: DepartmentByName

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon