EntityFrameworkQueryableExtensions.ThenInclude 方法

定义

重载

ThenInclude<TEntity,TPreviousProperty,TProperty>(IIncludableQueryable<TEntity,ICollection<TPreviousProperty>>, Expression<Func<TPreviousProperty,TProperty>>)

根据刚刚包含的相关类型,指定要进一步包括的其他相关数据。

ThenInclude<TEntity,TPreviousProperty,TProperty>(IIncludableQueryable<TEntity,IEnumerable<TPreviousProperty>>, Expression<Func<TPreviousProperty,TProperty>>)

根据刚刚包含的相关类型,指定要进一步包括的其他相关数据。

ThenInclude<TEntity,TPreviousProperty,TProperty>(IIncludableQueryable<TEntity,TPreviousProperty>, Expression<Func<TPreviousProperty,TProperty>>)

根据刚刚包含的相关类型,指定要进一步包括的其他相关数据。

ThenInclude<TEntity,TPreviousProperty,TProperty>(IIncludableQueryable<TEntity,ICollection<TPreviousProperty>>, Expression<Func<TPreviousProperty,TProperty>>)

根据刚刚包含的相关类型,指定要进一步包括的其他相关数据。

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)

类型参数

TEntity

正在查询的实体的类型。

TPreviousProperty

刚刚包含的实体的类型。

TProperty

要包含的相关实体的类型。

参数

source
IIncludableQueryable<TEntity,ICollection<TPreviousProperty>>

源查询。

navigationPropertyPath
Expression<Func<TPreviousProperty,TProperty>>

一个 lambda 表达式,表示要包含 (t = > Property1) 的导航属性。

返回

IIncludableQueryable<TEntity,TProperty>

包含相关数据的新查询。

示例

下面的查询显示包括单个级别的相关实体。

context.Blogs.Include(blog => blog.Posts);

下面的查询显示在同一分支中包括两个级别的实体。

context.Blogs
    .Include(blog => blog.Posts).ThenInclude(post => post.Tags);

下面的查询显示了包含多个级别和相关数据的分支。

context.Blogs
    .Include(blog => blog.Posts).ThenInclude(post => post.Tags).ThenInclude(tag => tag.TagInfo)
    .Include(blog => blog.Contributors);

适用于

ThenInclude<TEntity,TPreviousProperty,TProperty>(IIncludableQueryable<TEntity,IEnumerable<TPreviousProperty>>, Expression<Func<TPreviousProperty,TProperty>>)

根据刚刚包含的相关类型,指定要进一步包括的其他相关数据。

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)

类型参数

TEntity

正在查询的实体的类型。

TPreviousProperty

刚刚包含的实体的类型。

TProperty

要包含的相关实体的类型。

参数

source
IIncludableQueryable<TEntity,IEnumerable<TPreviousProperty>>

源查询。

navigationPropertyPath
Expression<Func<TPreviousProperty,TProperty>>

一个 lambda 表达式,表示要包含 (t = > Property1) 的导航属性。

返回

IIncludableQueryable<TEntity,TProperty>

包含相关数据的新查询。

示例

下面的查询显示包括单个级别的相关实体:

context.Blogs.Include(blog => blog.Posts)

下面的查询显示在同一分支中包括两个级别的实体:

context.Blogs
   .Include(blog => blog.Posts).ThenInclude(post => post.Tags)

以下查询显示了相关数据的多个级别和分支:

context.Blogs
   .Include(blog => blog.Posts).ThenInclude(post => post.Tags).ThenInclude(tag => tag.TagInfo)
   .Include(blog => blog.Contributors)

下面的查询显示在同一个分支上包含两个级别的实体,第二个级别使用强制转换在派生类型上进行:

context.Blogs.Include(blog => blog.Posts).ThenInclude(post => ((SpecialPost)post).SpecialTags)

下面的查询显示在同一分支上包含两个级别的实体,第二个级别使用运算符在派生类型上 as

context.Blogs.Include(blog => blog.Posts).ThenInclude(post => (post as SpecialPost).SpecialTags)

适用于

ThenInclude<TEntity,TPreviousProperty,TProperty>(IIncludableQueryable<TEntity,TPreviousProperty>, Expression<Func<TPreviousProperty,TProperty>>)

根据刚刚包含的相关类型,指定要进一步包括的其他相关数据。

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)

类型参数

TEntity

正在查询的实体的类型。

TPreviousProperty

刚刚包含的实体的类型。

TProperty

要包含的相关实体的类型。

参数

source
IIncludableQueryable<TEntity,TPreviousProperty>

源查询。

navigationPropertyPath
Expression<Func<TPreviousProperty,TProperty>>

一个 lambda 表达式,表示要包含 (t = > Property1) 的导航属性。

返回

IIncludableQueryable<TEntity,TProperty>

包含相关数据的新查询。

示例

下面的查询显示包括单个级别的相关实体:

context.Blogs.Include(blog => blog.Posts)

下面的查询显示在同一分支中包括两个级别的实体:

context.Blogs.Include(blog => blog.Posts).ThenInclude(post => post.Tags)

以下查询显示了相关数据的多个级别和分支:

context.Blogs
   .Include(blog => blog.Posts).ThenInclude(post => post.Tags).ThenInclude(tag => tag.TagInfo)
   .Include(blog => blog.Contributors)

下面的查询显示在同一分支上包含两个级别的实体,第二个级别是派生类型:

context.Blogs.Include(blog => blog.Posts).ThenInclude(post => ((SpecialPost)post).SpecialTags)

下面的查询显示在同一分支上包含两个级别的实体,第二个级别使用替代方法在派生类型上。

context.Blogs.Include(blog => blog.Posts).ThenInclude(post => (post as SpecialPost).SpecialTags)

适用于