Show / Hide Table of Contents

    ISqlModelMapper.LoadByPageAsync<TModel>(int currentIndex, int pageSize, params object[] parameters) Method

    .NET Standard 2.x

    Asynchronously retrieves data starting from a specified row according to the SQL query defined in a TModel class.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

    public Task<ILoadable<TModel>> LoadByPageAsync<TModel>(int currentIndex, int pageSize, params object[] parameters)
    

    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.

    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

    Task<ILoadable<TModel>>

    Returns a task that represents the asynchronous operation.

    Examples

    The following code example demonstrates how to load the specified page asynchronously according to the SQL query defined in the Department class.

    using Appeon.ApiDoc.Models.School;
    using System;
    using System.Threading;
    
    namespace Appeon.ApiDoc.ISqlModelMapperExamples
    {
        public class LoadByPageAsyncExample
        {
            private SchoolContext _context;
            
            public LoadByPageAsyncExample(SchoolContext dataContext)
            {
                // Sets the data context.
                _context = dataContext;
            }
    
            public async void Example1()
            {
                var mapper = _context.SqlModelMapper;
                
                // Loads the departments.
                var depts = (await mapper.LoadAsync<Department>()).ToList();
                
                Console.WriteLine("All departments:");
                foreach (var department in depts)
                {
                    Console.WriteLine(department.Name);
                }
                
                Console.WriteLine();
                
                // Loads the first page (2 records per page)
                var deptsPage1 = (await mapper.LoadByPageAsync<Department>(0, 2)).ToList();
                
                Console.WriteLine("Departments (Page 1):");
                foreach (var department in deptsPage1)
                {
                    Console.WriteLine(department.Name);
                }
                
                /* The code produces the following output:
                
                    All departments:
                    Engineering
                    English
                    Economics
                    Mathematics
                    
                    Departments (Page 1):
                    Engineering
                    English
                */
            }
        }
    }
    

    Example Refer To

    Model Class: Department

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon