EntityFrameworkQueryableExtensions.ThenInclude 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
重载
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 => t.Property1)。
返回
包含相关数据的新查询。
示例
以下查询显示包括单个级别的相关实体:
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 => t.Property1)。
返回
包含相关数据的新查询。
示例
以下查询显示包括单个级别的相关实体:
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)
注解
有关详细信息和示例,请参阅 “加载相关实体 ”。
适用于
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 => t.Property1)。
返回
包含相关数据的新查询。
示例
以下查询显示包含单个相关实体级别。
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);