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