ISqlModelMapper.LoadEmbedded<TModel>(TModel model, params object[] parameters) Method
.NET Standard 2.x
Obtains an IEmbeddedLoadable<TModel>
object, which can be used to load the embedded property of a TModel
instance.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
public IEmbeddedLoadable<TModel> LoadEmbedded<TModel>(TModel model, params object[] parameters);
Type Parameters
TModel
The type of a model class.
Parameters
model
System.TModel
A TModel
instance which has defined one or more embedded properties (by applying the ModelEmbedded attribute or the SqlEmbedded attribute).
parameters
System.Object[]
(Optional) One or more values that you want to use as retrieval arguments in the SQL SELECT statement defined in TModel
.
These parameters will not be used to retrieve data for all properties in TModel
object, but used to process the embedded property), because the embedded property) may have reference to these TModel
parameters.
Returns
SnapObjects.Data.IEmbeddedLoadable<TModel>
Returns an interface that can load one or more embedded properties) of a TModel
object.
Remarks
This method does not actually retrieve the master model or its embedded property), instead it returns an IEmbeddedLoadable<TModel>
object whose methods will be used to retrieve and load data.
To retrieve and load data of the master model and the detail model at the same time, use the ISqlModelMapper.Load method instead.
Examples
The following code example demonstrates how to load the courses for a department.
using Appeon.ApiDoc.Models.School;
using System;
namespace Appeon.ApiDoc.ISqlModelMapperExamples
{
public class LoadEmbeddedExample
{
private SchoolContext _context;
public LoadEmbeddedExample(SchoolContext dataContext)
{
// Sets the data context.
_context = dataContext;
}
public void Example()
{
var mapper = _context.SqlModelMapper;
// Loads the information for department of Engineering and
// it doesn't load the courses here.
var dept = mapper.Load<DepartmentInfo>()
.ToList()
.Find(o => o.Name == "Engineering");
Console.WriteLine("Department: {0}",
dept.Name);
// Loads the courses that belong to the department of Engineering.
mapper.LoadEmbedded(dept).Include(o => o.Courses);
Console.WriteLine();
Console.WriteLine("Courses:");
foreach (CourseInfo course in dept.Courses)
{
Console.WriteLine(course.Title);
}
/* The code produces the following output:
Department: Engineering
Courses:
Chemistry
Physics
*/
}
}
}
Example Refer To
Model Classes: DepartmentInfo CourseInfo
Applies to
.NET Standard
2.x