Include
The Include
feature is used to indicate to the ORM that a related navigation property should be returned along with the base record being queried. It is used to expand the amount of related data being returned with an entity, providing eager loading of related data.
Compatible with the following providers:
Note: Lazy-loading is not recommended in web-based .NET applications.
Below is a specification that loads a Company entity along with its collection of Stores.
public class CompanySpec : Specification<Company>
{
public CompanySpec(int id)
{
Query.Where(company => company.Id == id)
.Include(x => x.Stores);
}
}
ThenInclude
The ThenInclude
feature is used to indicate to the ORM that a related property of a previously Include
d property should be returned with a query result.
Compatible with the following providers:
Below is a specification that loads a Company entity along with its collection of Stores, then each Store’s collection of Products.
public class CompanySpec : Specification<Company>
{
public CompanySpec(int id)
{
Query.Where(company => company.Id == id)
.Include(x => x.Stores)
.ThenInclude(x => x.Products);
}
}