ISqlModelMapper.LoadAllByPage<TModel>(int currentIndex, int pageSize) Method
.NET Standard 2.x
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 ILoadable<TModel> LoadAllByPage<TModel>(int currentIndex, int pageSize);
Type Parameters
TModel
The type of a model class.
Parameters
currentIndex
System.Int32
The zero-based index of the first record in the page.
pageSize
System.Int32
The count of rows in each page.
Returns
SnapObjects.Data.ILoadable<TModel>
Returns the ILoadable<TModel>
interface whose methods can be used to further obtain the result set, or perform data operations such as embedded queries.
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 load the specified page according to the SQL query (without the Where clause) defined by the DepartmentByName
class.
using SnapObjects.Data;
using Appeon.ApiDoc.Models.School;
using System;
using System.Collections.Generic;
namespace Appeon.ApiDoc.ISqlModelMapperExamples
{
public class LoadAllByPageExample
{
private SchoolContext _context;
public LoadAllByPageExample(SchoolContext dataContext)
{
// Sets the data context.
_context = dataContext;
}
public void Example()
{
var mapper = _context.SqlModelMapper;
// Loads the department of Engineering using LoadAll.
// It retrieves all records from Department table.
var depts = mapper.LoadAll<DepartmentByName>().ToList();
Console.WriteLine("All departments:");
foreach (var department in depts)
{
Console.WriteLine(department.Name);
}
Console.WriteLine();
// Loads the first page only (2 records per page)
var deptsPage1 = mapper.LoadAllByPage<DepartmentByName>(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: DepartmentByName
Applies to
.NET Standard
2.x