ThenIncludeQueryable Class
Namespace: PTS
Assembly: PTS.DomainFramework.Includers.dll
Syntax
public static class ThenIncludeQueryable
Inheritance
Methods
IncludeRelated<TFirst, TSource, TPrevious, TRelated>(ThenIncluder<TFirst, TPrevious, TSource>, IQueryable<TRelated>, out Lot<TSource, TRelated>, Expression<Func<TFirst, TSource, TRelated, Boolean>>)
Declaration
public static RelatedIncluder<TFirst, TSource, TRelated> IncludeRelated<TFirst, TSource, TPrevious, TRelated>(this ThenIncluder<TFirst, TPrevious, TSource> parent, IQueryable<TRelated> right, out Lot<TSource, TRelated> collection, Expression<Func<TFirst, TSource, TRelated, bool>> predicate = null)
Parameters
Type | Name | Description |
---|---|---|
ThenIncluder<TFirst, TPrevious, TSource> | parent | |
System.Linq.IQueryable<TRelated> | right | |
Lot<TSource, TRelated> | collection | |
System.Linq.Expressions.Expression<System.Func<TFirst, TSource, TRelated, System.Boolean>> | predicate |
Returns
Type | Description |
---|---|
RelatedIncluder<TFirst, TSource, TRelated> |
Type Parameters
Name | Description |
---|---|
TFirst | |
TSource | |
TPrevious | |
TRelated |
ThenInclude<TFirst, TSource, TRelated>(Includer<TFirst, TSource>, IQueryable<TRelated>, out Lot<TSource, TRelated>, Expression<Func<TFirst, TSource, TRelated, Boolean>>)
Specifies entity related to the previous 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 ThenRequire
method.
If you wish to include additional entities related to the source entitiy, then chain call to the same method ThenInclude
with additional related query as parameter.
If you wish to include additional related entities for included entities, then chain a call to methods IncludeContainer.IncludeRelated
or IncludeContainer.RequireRelated
after this call.
If you wish to include additional entities related to the first entitiy, then chain call to the method Include
or Require
with additional related query as parameter.
Declaration
public static ThenIncluder<TFirst, TSource, TRelated> ThenInclude<TFirst, TSource, TRelated>(this Includer<TFirst, TSource> source, IQueryable<TRelated> related, out Lot<TSource, TRelated> collection, Expression<Func<TFirst, TSource, TRelated, bool>> predicate = null)
Parameters
Type | Name | Description |
---|---|---|
Includer<TFirst, TSource> | source | Previous include container in call chain. |
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<TFirst, 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 |
---|---|
ThenIncluder<TFirst, TSource, TRelated> | Container for chaining with included data returned via reference to ILot collection. |
Type Parameters
Name | Description |
---|---|
TFirst | The first type in call chain. |
TSource | The type of entity included in previous join to get related entities for. |
TRelated | The type of the related entity to be included. |
Remarks
This is an alternative method to EntityFrameworkQueryableExtensions.ThenInclude
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.Events, out var events )
.ThenInclude( context.EventTimes, out var times );
foreach( User user in data )
{
Console.WriteLine( $"User {user.Name}:" );
// Loop through contacts
foreach( Event ev in events[user] )
{
Console.WriteLine( $"Event: {ev.Label}" );
// Loop through times for given event
foreach( EventTime time in times[ev] )
{
Console.WriteLine( $"Time slot from {time.StartsOn} until {time.EndsOn}" );
}
}
}
ThenInclude<TFirst, TPrevious, TSource, TRelated>(RelatedIncluder<TFirst, TPrevious, TSource>, IQueryable<TRelated>, out Lot<TSource, TRelated>, Expression<Func<TFirst, TSource, TRelated, Boolean>>)
Declaration
public static ThenIncluder<TFirst, TSource, TRelated> ThenInclude<TFirst, TPrevious, TSource, TRelated>(this RelatedIncluder<TFirst, TPrevious, TSource> source, IQueryable<TRelated> related, out Lot<TSource, TRelated> collection, Expression<Func<TFirst, TSource, TRelated, bool>> predicate = null)
Parameters
Type | Name | Description |
---|---|---|
RelatedIncluder<TFirst, TPrevious, TSource> | source | |
System.Linq.IQueryable<TRelated> | related | |
Lot<TSource, TRelated> | collection | |
System.Linq.Expressions.Expression<System.Func<TFirst, TSource, TRelated, System.Boolean>> | predicate |
Returns
Type | Description |
---|---|
ThenIncluder<TFirst, TSource, TRelated> |
Type Parameters
Name | Description |
---|---|
TFirst | |
TPrevious | |
TSource | |
TRelated |
ThenInclude<TFirst, TSource, TPrevious, TRelated>(ThenIncluder<TFirst, TSource, TPrevious>, IQueryable<TRelated>, out Lot<TSource, TRelated>, Expression<Func<TFirst, TSource, TRelated, Boolean>>)
Specifies entity related to the previous 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 ThenRequire
method.
If you wish to include additional entities related to the source entitiy, then chain call to the same method ThenInclude
with additional related query as parameter.
If you wish to include additional related entities for included entities, then chain a call to methods IncludeContainer.IncludeRelated
or IncludeContainer.RequireRelated
after this call.
If you wish to include additional entities related to the first entitiy, then chain call to the method Include
or Require
with additional related query as parameter.
Declaration
public static ThenIncluder<TFirst, TSource, TRelated> ThenInclude<TFirst, TSource, TPrevious, TRelated>(this ThenIncluder<TFirst, TSource, TPrevious> source, IQueryable<TRelated> related, out Lot<TSource, TRelated> collection, Expression<Func<TFirst, TSource, TRelated, bool>> predicate = null)
Parameters
Type | Name | Description |
---|---|---|
ThenIncluder<TFirst, TSource, TPrevious> | source | Previous include container in call chain. |
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<TFirst, 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 |
---|---|
ThenIncluder<TFirst, TSource, TRelated> | Container for chaining with included data returned via reference to ILot collection. |
Type Parameters
Name | Description |
---|---|
TFirst | The first type in call chain. |
TSource | The type of entity in the chain to get related entities for. |
TPrevious | The type of entity included in previous join. |
TRelated | The type of the related entity to be included. |
Remarks
This is an alternative method to EntityFrameworkQueryableExtensions.ThenInclude
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.Events, out var events )
.ThenInclude( context.EventTimes.Take( 1 ), out var times );
.ThenInclude( context.EventMembers, out var members );
foreach( User user in data )
{
Console.WriteLine( $"User {user.Name}:" );
// Loop through contacts
foreach( Event ev in events[user] )
{
Console.WriteLine( $"Event: {ev.Label}" );
EventTime startsOn in times[ev];
Console.WriteLine( $"Event starts on {time.StartsOn}" );
Console.WriteLine( $"Event has {members.Count} participants" );
}
}