ISqlModelMapper.LoadAll<TModel>() Method
.NET Standard 2.x
Retrieves data from the database 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> LoadAll<TModel>();
Type Parameters
TModel
The type of a model class.
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.
If TModel
has properties that apply attributes such as SqlCompute, NotMapped
etc., LoadAll and LoadByKey cannot load data of such properties. In such case, use Load instead of LoadAll and LoadByKey.
Examples
The following code example demonstrates how to load departments without the Where clause 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 LoadAllExample
{
private SchoolContext _context;
public LoadAllExample(SchoolContext dataContext)
{
// Sets the data context.
_context = dataContext;
}
public void Example()
{
var mapper = _context.SqlModelMapper;
// Loads the department of Engineering.
// Passes in the argument by a value
int count = mapper.Load<DepartmentByName>("Engineering").ToList().Count;
Console.WriteLine("Count (Load): {0}", count);
// Loads the department of Engineering using LoadAll
// It retrieves all records from Department table.
count = mapper.LoadAll<DepartmentByName>().ToList().Count;
Console.WriteLine("Count (LoadAll): {0}", count);
/* The code produces the following output:
Count (Load): 1
Count (LoadAll): 4
*/
}
}
}
Example Refer To
Model Class: DepartmentByName
Applies to
.NET Standard
2.x