簡體   English   中英

如何在OfType()之后使用Include()?

[英]How to use Include() after OfType()?

我試圖在Entity Framework模型中急於加載派生類的屬性。

在包含使用Include()的屬性之前,我已經閱讀了所有必須首先使用OfType()過濾集合 地方

var persons = Context.Persons
                     .OfType<Employee>()
                     .Include("Compensation")

我不知道如何讓Include()工作,因為在我的情況下,Persons是DbSet,OfType()返回IQueryable而IQueryable沒有定義Include()方法。

放置這個:

using System.Data.Entity;

在您的使用列表中,之后您將能夠使用DbExtensions類中的Include擴展方法系列:

    public static IQueryable<T> Include<T, TProperty>(this IQueryable<T> source, Expression<Func<T, TProperty>> path) where T : class;
    public static IQueryable<T> Include<T>(this IQueryable<T> source, string path) where T : class;
    public static IQueryable Include(this IQueryable source, string path);

他們接受IQueryable作為第一個參數,並且還有強類型的,哪個更好,然后是Include(String)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM