EntityFrameworkQueryableExtensions.ThenInclude Method     
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
| ThenInclude<TEntity,TPreviousProperty,TProperty>(IIncludableQueryable<TEntity,TPreviousProperty>, Expression<Func<TPreviousProperty,TProperty>>) | 
						 Specifies additional related data to be further included based on a related type that was just included.  | 
        	
| ThenInclude<TEntity,TPreviousProperty,TProperty>(IIncludableQueryable<TEntity, IEnumerable<TPreviousProperty>>, Expression<Func<TPreviousProperty, TProperty>>) | 
						 Specifies additional related data to be further included based on a related type that was just included.  | 
        	
| ThenInclude<TEntity,TPreviousProperty,TProperty>(IIncludableQueryable<TEntity, ICollection<TPreviousProperty>>, Expression<Func<TPreviousProperty, TProperty>>) | 
						 Specifies additional related data to be further included based on a related type that was just included.  | 
        	
ThenInclude<TEntity,TPreviousProperty,TProperty>(IIncludableQueryable<TEntity,TPreviousProperty>, Expression<Func<TPreviousProperty,TProperty>>)
Specifies additional related data to be further included based on a related type that was just included.
public static Microsoft.EntityFrameworkCore.Query.IIncludableQueryable<TEntity,TProperty> ThenInclude<TEntity,TPreviousProperty,TProperty>(this Microsoft.EntityFrameworkCore.Query.IIncludableQueryable<TEntity,TPreviousProperty> source, System.Linq.Expressions.Expression<Func<TPreviousProperty,TProperty>> navigationPropertyPath) where TEntity : class;
	static member ThenInclude : Microsoft.EntityFrameworkCore.Query.IIncludableQueryable<'Entity, 'PreviousProperty (requires 'Entity : null)> * System.Linq.Expressions.Expression<Func<'PreviousProperty, 'Property>> -> Microsoft.EntityFrameworkCore.Query.IIncludableQueryable<'Entity, 'Property (requires 'Entity : null)> (requires 'Entity : null)
	<Extension()>
Public Function ThenInclude(Of TEntity As Class, TPreviousProperty As Class, TProperty As Class) (source As IIncludableQueryable(Of TEntity, TPreviousProperty), navigationPropertyPath As Expression(Of Func(Of TPreviousProperty, TProperty))) As IIncludableQueryable(Of TEntity, TProperty)
    Type Parameters
- TEntity
 
The type of entity being queried.
- TPreviousProperty
 
The type of the entity that was just included.
- TProperty
 
The type of the related entity to be included.
Parameters
- source
 - IIncludableQueryable<TEntity,TPreviousProperty>
 
The source query.
- navigationPropertyPath
 - Expression<Func<TPreviousProperty,TProperty>>
 
A lambda expression representing the navigation property to be included (t => t.Property1).
Returns
A new query with the related data included.
Examples
The following query shows including a single level of related entities:
context.Blogs.Include(blog => blog.Posts)
The following query shows including two levels of entities on the same branch:
context.Blogs.Include(blog => blog.Posts).ThenInclude(post => post.Tags)
The following query shows including multiple levels and branches of related data:
context.Blogs
   .Include(blog => blog.Posts).ThenInclude(post => post.Tags).ThenInclude(tag => tag.TagInfo)
   .Include(blog => blog.Contributors)
The following query shows including two levels of entities on the same branch, second one being on derived type:
context.Blogs.Include(blog => blog.Posts).ThenInclude(post => ((SpecialPost)post).SpecialTags)
The following query shows including two levels of entities on the same branch, second one being on derived type using alternative method.
context.Blogs.Include(blog => blog.Posts).ThenInclude(post => (post as SpecialPost).SpecialTags)
    	Remarks
See Loading related entities for more information and examples.
Applies to
ThenInclude<TEntity,TPreviousProperty,TProperty>(IIncludableQueryable<TEntity, IEnumerable<TPreviousProperty>>, Expression<Func<TPreviousProperty, TProperty>>)
Specifies additional related data to be further included based on a related type that was just included.
public static Microsoft.EntityFrameworkCore.Query.IIncludableQueryable<TEntity,TProperty> ThenInclude<TEntity,TPreviousProperty,TProperty>(this Microsoft.EntityFrameworkCore.Query.IIncludableQueryable<TEntity,System.Collections.Generic.IEnumerable<TPreviousProperty>> source, System.Linq.Expressions.Expression<Func<TPreviousProperty,TProperty>> navigationPropertyPath) where TEntity : class;
	static member ThenInclude : Microsoft.EntityFrameworkCore.Query.IIncludableQueryable<'Entity, seq<'PreviousProperty> (requires 'Entity : null)> * System.Linq.Expressions.Expression<Func<'PreviousProperty, 'Property>> -> Microsoft.EntityFrameworkCore.Query.IIncludableQueryable<'Entity, 'Property (requires 'Entity : null)> (requires 'Entity : null)
	<Extension()>
Public Function ThenInclude(Of TEntity As Class, TPreviousProperty As Class, TProperty As Class) (source As IIncludableQueryable(Of TEntity, IEnumerable(Of TPreviousProperty)), navigationPropertyPath As Expression(Of Func(Of TPreviousProperty, TProperty))) As IIncludableQueryable(Of TEntity, TProperty)
    Type Parameters
- TEntity
 
The type of entity being queried.
- TPreviousProperty
 
The type of the entity that was just included.
- TProperty
 
The type of the related entity to be included.
Parameters
- source
 - IIncludableQueryable<TEntity,IEnumerable<TPreviousProperty>>
 
The source query.
- navigationPropertyPath
 - Expression<Func<TPreviousProperty,TProperty>>
 
A lambda expression representing the navigation property to be included (t => t.Property1).
Returns
A new query with the related data included.
Examples
The following query shows including a single level of related entities:
context.Blogs.Include(blog => blog.Posts)
The following query shows including two levels of entities on the same branch:
context.Blogs
   .Include(blog => blog.Posts).ThenInclude(post => post.Tags)
The following query shows including multiple levels and branches of related data:
context.Blogs
   .Include(blog => blog.Posts).ThenInclude(post => post.Tags).ThenInclude(tag => tag.TagInfo)
   .Include(blog => blog.Contributors)
The following query shows including two levels of entities on the same branch, second one being on derived type using casting:
context.Blogs.Include(blog => blog.Posts).ThenInclude(post => ((SpecialPost)post).SpecialTags)
          The following query shows including two levels of entities on the same branch, second one being on derived type using
          the as operator.
context.Blogs.Include(blog => blog.Posts).ThenInclude(post => (post as SpecialPost).SpecialTags)
    	Remarks
See Loading related entities for more information and examples.
Applies to
ThenInclude<TEntity,TPreviousProperty,TProperty>(IIncludableQueryable<TEntity, ICollection<TPreviousProperty>>, Expression<Func<TPreviousProperty, TProperty>>)
Specifies additional related data to be further included based on a related type that was just included.
public static Microsoft.EntityFrameworkCore.Query.IIncludableQueryable<TEntity,TProperty> ThenInclude<TEntity,TPreviousProperty,TProperty>(this Microsoft.EntityFrameworkCore.Query.IIncludableQueryable<TEntity,System.Collections.Generic.ICollection<TPreviousProperty>> source, System.Linq.Expressions.Expression<Func<TPreviousProperty,TProperty>> navigationPropertyPath) where TEntity : class;
	static member ThenInclude : Microsoft.EntityFrameworkCore.Query.IIncludableQueryable<'Entity, System.Collections.Generic.ICollection<'PreviousProperty> (requires 'Entity : null)> * System.Linq.Expressions.Expression<Func<'PreviousProperty, 'Property>> -> Microsoft.EntityFrameworkCore.Query.IIncludableQueryable<'Entity, 'Property (requires 'Entity : null)> (requires 'Entity : null)
	<Extension()>
Public Function ThenInclude(Of TEntity As Class, TPreviousProperty As Class, TProperty As Class) (source As IIncludableQueryable(Of TEntity, ICollection(Of TPreviousProperty)), navigationPropertyPath As Expression(Of Func(Of TPreviousProperty, TProperty))) As IIncludableQueryable(Of TEntity, TProperty)
    Type Parameters
- TEntity
 
The type of entity being queried.
- TPreviousProperty
 
The type of the entity that was just included.
- TProperty
 
The type of the related entity to be included.
Parameters
- source
 - IIncludableQueryable<TEntity,ICollection<TPreviousProperty>>
 
The source query.
- navigationPropertyPath
 - Expression<Func<TPreviousProperty,TProperty>>
 
A lambda expression representing the navigation property to be included (t => t.Property1).
Returns
A new query with the related data included.
Examples
The following query shows including a single level of related entities.
context.Blogs.Include(blog => blog.Posts);
The following query shows including two levels of entities on the same branch.
context.Blogs
    .Include(blog => blog.Posts).ThenInclude(post => post.Tags);
The following query shows including multiple levels and branches of related data.
context.Blogs
    .Include(blog => blog.Posts).ThenInclude(post => post.Tags).ThenInclude(tag => tag.TagInfo)
    .Include(blog => blog.Contributors);