ISqlModelMapper.Load<TModel>(params object[] parameters) Method
.NET Standard 2.x
Retrieves data according to the SQL query defined in a TModel
class.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
public ILoadable<TModel> Load<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
SnapObjects.Data.ILoadable<TModel>
Returns a ILoadable<TModel>
object whose methods can be used to further obtain the result set, or perform data operations such as embedded queries.
Examples
The following code example demonstrates how to load departments according to a model class.
using SnapObjects.Data;
using Appeon.ApiDoc.Models.School;
using System;
using System.Collections.Generic;
namespace Appeon.ApiDoc.ISqlModelMapperExamples
{
public class LoadExample
{
private SchoolContext _context;
public LoadExample(SchoolContext dataContext)
{
// Sets the data context.
_context = dataContext;
}
public void Example()
{
var mapper = _context.SqlModelMapper;
// Loads all departments and gets the list.
List<Department> depts = mapper.Load<Department>().ToList();
Console.WriteLine("The list of departments:");
foreach (Department dept in depts)
{
Console.WriteLine(dept.Name);
}
// Loads the department of Engineering.
var engineering = mapper.Load<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"));
/* 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 350,000
*/
}
}
}
Example Refer To
Model Classes: Department DepartmentByName
Applies to
.NET Standard
2.x