ISqlModelMapper.LoadAsync<TModel>(params object[] parameters) Method
.NET Standard 2.x
Asynchronously retrieves data according to the SQL query defined in a TModel
class.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
public Task<ILoadable<TModel>> LoadAsync<TModel>(params object[] parameters)
Type Parameters
TModel
The type of a model class.
Parameters
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 departments asynchronously according to a model 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 LoadAsyncExample
{
private readonly SchoolContext _context;
public LoadAsyncExample(SchoolContext dataContext)
{
// Sets the data context.
_context = dataContext;
}
public async Task<int> Example1()
{
var mapper = _context.SqlModelMapper;
// Asynchronously loads all departments and gets the list.
var depts = (await mapper.LoadAsync<Department>()).ToList();
Console.WriteLine("The list of departments:");
foreach (Department dept in depts)
{
Console.WriteLine(dept.Name);
}
// Asynchronously loads the department of Engineering.
var engineering = (await mapper.LoadAsync<DepartmentByName>("Engineering"))
.FirstOrDefault();
Console.WriteLine();
Console.WriteLine("The department of Engineering:");
Console.WriteLine("Department ID is {0}", engineering.DepartmentID);
Console.WriteLine("Name is {0}", engineering.Name);
Console.WriteLine("Budget is {0}", engineering.Budget.ToString("N0"));
return depts.Count;
/* The code produces the following output:
The list of departments:
Engineering
English
Economics
Mathematics
The department of Engineering:
Department ID is 1
Name is Engineering
Budget is 330,000
*/
}
}
}
Example Refer To
Model Classes: Department DepartmentByName
Applies to
.NET Standard
2.x