IEmbeddedLoadable<TModel> Interface
.NET Standard 2.x
Provides a series of methods for manipulating the data in the embedded properties of TModel.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
public interface IEmbeddedLoadable<TModel>;
Properties
| Name | Return type | Description |
|---|---|---|
| MasterModel | TModel | Gets a reference to the master model instance which is an argument when the ISqlModelMapper.TrackMaster method is called. |
Methods
| Name | Return type | Description |
|---|---|---|
| Include(Expression<Func<TModel, object>> property, bool cascade = false) | IEmbeddedLoadable<TModel> | Loads the specified embedded property in TModel for all rows. |
| IncludeAll(bool cascade = false) | IEmbeddedLoadable<TModel> | Loads all the embedded properties in TModel for all rows. |
| IncludeAsync(Expression<Func<TModel, object>> property, bool cascade = false, CancellationToken cancellationToken = default) | Task<IEmbeddedLoadable<TModel>> | Asynchronously loads the specified embedded property in TModel for all rows. |
| IncludeAllAsync(bool cascade = false, CancellationToken cancellationToken = default) | Task<IEmbeddedLoadable<TModel>> | Asynchronously loads all the embedded properties in TModel for all rows. |
Remarks
The ISqlModelMapper.LoadEmbedded method will return an IEmbeddedLoadable object whose methods can be used to manipulate the data in the embedded properties of TModel.
For example, the IEmbeddedLoadable.Include method can be used to load the data for an embedded property of TModel.
Examples
The following code example demonstrates how to load students who have selected the Poetry course.
using Appeon.ApiDoc.Models.School;
using System;
namespace Appeon.ApiDoc.IEmbeddedLoadableExamples
{
public class IEmbeddedLoadableExample
{
private SchoolContext _context;
public IEmbeddedLoadableExample(SchoolContext dataContext)
{
// Sets the data context.
_context = dataContext;
}
public void Example()
{
var mapper = _context.SqlModelMapper;
// Loads the course of Poetry (Course ID = 2030).
var course = mapper.LoadByKey<CourseInfo>(2030).FirstOrDefault();
// Loads students.
var students = mapper.LoadEmbedded(course)
.Include(o=>o.Students)
.MasterModel
.Students;
foreach (CourseStudentInfo student in students)
{
Console.WriteLine("Course ID is {0}.",
student.CourseID);
Console.WriteLine("Student ID is {0}.",
student.StudentID);
}
/*The code produces the following output is
Course ID is 2030.
Student ID is 2.
Course ID is 2030.
Student ID is 3.
*/
}
}
}