IncludeQueryable Class
Namespace: PTS
Assembly: PTS.DomainFramework.Includers.dll
Syntax
public static class IncludeQueryable
Inheritance
Methods
Include<TSource, TRelated>(Includer<TSource>, IQueryable<TRelated>, out Lot<TSource, TRelated>, Expression<Func<TSource, TRelated, Boolean>>)
Specifies entity related to the first entity in the call chain to be included in the query result with left join. Related entites are returned via out
parameter as ILot collection.
Related entities are non-blocking, the result includes source entities that do not have any related dependants from related query. For blocking inclusion use the Require
method.
If you wish to include additional entities related to the source entitiy, then chain call to the same method with additional related query as parameter.
If you wish to include additional related entities for included entities, then chain a call to methods IncludeContainer.ThenInclude
or IncludeContainer.ThenRequire
after this call.
Declaration
public static Includer<TSource, TRelated> Include<TSource, TRelated>(this Includer<TSource> parent, IQueryable<TRelated> right, out Lot<TSource, TRelated> collection, Expression<Func<TSource, TRelated, bool>> predicate = null)
Parameters
Type | Name | Description |
---|---|---|
Includer<TSource> | parent | Previous include container in call chain. |
System.Linq.IQueryable<TRelated> | right | |
Lot<TSource, TRelated> | collection | ILot collection with included entities accessible with the source entity as index key. |
System.Linq.Expressions.Expression<System.Func<TSource, TRelated, System.Boolean>> | predicate | Boolean lambda expression with source, previous and related entities as parameters for relative filtering in the query. |
Returns
Type | Description |
---|---|
Includer<TSource, TRelated> | Container for chaining with included data returned via reference to ILot collection. |
Type Parameters
Name | Description |
---|---|
TSource | The first type in call chain to get related entities for. |
TRelated | The type of the related entity to be included. |
Remarks
This is an alternative method to EntityFrameworkQueryableExtensions.Include
for inclusion of related entities without navigation properties,
generally applicable in situations when the entities are defined in separate assemblies. If both source and related types are within
the same assembly with available navigation properties, it is recommended that you use the extension method provided by EF Core.
Examples
var searchWord = "John Doe";
var data = context.Users.Where( u => u.Name.Contains( searchWord ) )
.Include( context.Contacts, out var contacts )
.Include( context.Locale.Take( 1 ), out var locales );
foreach( User user in data )
{
Console.WriteLine( $"User {user.Name}:" );
// Loop through contacts
foreach( Contact contact in contacts[user] )
Console.WriteLine( $"Email: {contact.Value}" );
// Get user's locale
Locale locale = locales[user];
Console.WriteLine( $"Language: {locale.Language}" );
}
Include<TSource, TRelated>(IQueryable<TSource>, IQueryable<TRelated>, out Lot<TSource, TRelated>, Expression<Func<TSource, TRelated, Boolean>>)
Specifies related entity to include in the query result with left join. Related entites are returned via out
parameter as ILot collection.
Related entities are non-blocking, the result includes source entities that do not have any related dependants from related query. For blocking inclusion use the Require
method.
If you wish to include additional entities related to the source entitiy, then chain call to the same method with additional related query as parameter.
If you wish to include additional related entities for included entities, then chain a call to methods IncludeContainer.ThenInclude
or IncludeContainer.ThenRequire
after this call.
Declaration
public static Includer<TSource, TRelated> Include<TSource, TRelated>(this IQueryable<TSource> source, IQueryable<TRelated> related, out Lot<TSource, TRelated> collection, Expression<Func<TSource, TRelated, bool>> predicate = null)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.IQueryable<TSource> | source | The source query. |
System.Linq.IQueryable<TRelated> | related | Query fetching related entity to be included. |
Lot<TSource, TRelated> | collection | ILot collection with included entities accessible with the source entity as index key. |
System.Linq.Expressions.Expression<System.Func<TSource, TRelated, System.Boolean>> | predicate | Boolean lambda expression with source and related entities as parameters for relative filtering in the query. |
Returns
Type | Description |
---|---|
Includer<TSource, TRelated> | Container for chaining with included data returned via reference to ILot collection. |
Type Parameters
Name | Description |
---|---|
TSource | The type of entity being queried. |
TRelated | The type of the related entity to be included. |
Remarks
This is an alternative method to EntityFrameworkQueryableExtensions.Include
for inclusion of related entities without navigation properties,
generally applicable in situations when the entities are defined in separate assemblies. If both source and related types are within
the same assembly with available navigation properties, it is recommended that you use the extension method provided by EF Core.
Examples
var searchWord = "John Doe";
var data = context.Users.Where( u => u.Name.Contains( searchWord ) )
.Include( context.Contacts.Where( c => c.Type == ContactType.Email ), out var contacts );
foreach( User user in data )
{
Console.WriteLine( $"User {user.Name}:" );
// Loop through contacts
foreach( Contact contact in contacts[user] )
Console.WriteLine( $"Email: {contact.Value}" );
}