Show / Hide Table of Contents

    IDataStoreBase.RetrieveByPageAsync(int currentIndex, int pageSize, object[] arguments, CancellationToken cancellationToken) Method

    .NET Standard 2.x

    Asynchronously retrieves a number of rows in the database starting from the specified row. If arguments are included, the argument values are used for the retrieval arguments in the SQL SELECT statement for the DataStore.

    Namespace: DWNet.Data

    Assembly: DWNet.Data.dll

    Syntax

    public Task<int> RetrieveByPageAsync(int currentIndex, int pageSize, object[] arguments, CancellationToken cancellationToken)
    

    Pararmeters

    currentIndex System.Int32

    The index number of the current row in the DataStore.

    pageSize System.Int322

    Number of rows to be retrieved.

    arguments System.Object[]

    One or more values that you want to use as retrieval arguments in the SQL SELECT statement defined in the DataStore.

    NOTE: This parameter is required.

    cancellationToken CancellationToken

    A cancellation token that can be used by other objects or threads to receive notice of cancellation.

    Returns

    Task<int>

    Returns a task that represents the asynchronous operation.

    Examples

    The following code example demonstrates how to retrieve rows by page asynchronously from the database for DataStore. It uses a CancellationTokenSource type parameter to make this operation cancelable.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading;
    using System.Threading.Tasks;
    using DWNet.Data;
    
    namespace Appeon.ApiDoc.IDataStoreBaseExamples
    {
        public class RetrieveByPageAsyncExample
        {
            private readonly SchoolContext _context;
            
            public RetrieveByPageAsyncExample(SchoolContext dataContext)
            {
                // Sets the data context
                _context = dataContext;
            }
    
            public async Task<int> Example2(CancellationTokenSource cts)
            {
                // Instantiates a DataStore object with datawindow: d_department.
                var datastore = new DataStore("d_department", _context);
                
                int result = 0;
                try
                {
                    // Gets two rows of data starting from the first row
                    // If a task has been cancelled, the call to the 
                    // DataStore.RetrieveByPageAsync method throws an OperationCanceledException.
                    result = await datastore.RetrieveByPageAsync(1, 2, new object[]{ 1 }, cts.Token);
                    
                    Console.WriteLine("Rowcount: {0}", datastore.RowCount);
                }
                catch (OperationCanceledException e)
                {
                    // The operation was cancelled before completion.
                    Console.WriteLine(e.Message);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
                finally
                {
                    cts.Dispose();
                }
                
                return result;
                
                /*This code produces the following output:
                 
                    A task was canceled. 
                */
            }
        }
    }
    

    Example Refer To

    Model Class: D_Department
    DataWindow File: d_department

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon