EntityFrameworkQueryableExtensions.ThenInclude 方法

定義

多載

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

指定要根據剛包含的相關類型進一步包含的其他相關資料。

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

指定要根據剛包含的相關類型進一步包含的其他相關資料。

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

指定要根據剛包含的相關類型進一步包含的其他相關資料。

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, 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, 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);

適用於