【问题标题】:Not finding .Include() method in my EF implementing Generic repository在我的 EF 实现通用存储库中找不到 .Include() 方法
【发布时间】:2013-03-02 23:13:17
【问题描述】:

我正在使用通用存储库从上层包装 DbContext 和 DbSet 类。 但是,在某些查询中,我需要使用“.Include()”方法来包含导航属性。但我无法在 reting IQueryable 的存储库方法中找到这些方法

喜欢,

this.repository.GetQuery<GeneralCalendarDates>()

虽然我可以在这里使用 .ToList(),但它没有包含方法。

知道这里有什么问题吗?

【问题讨论】:

    标签: entity-framework repository-pattern


    【解决方案1】:

    Include for IQueryable&lt;T&gt; 是在程序集EntityFramework.dll 的命名空间System.Data.Entity 中实现的扩展方法。所以你的项目必须引用这个程序集并且你必须添加

    using System.Data.Entity;
    

    在代码文件的开头。它将使Include 的基于字符串和lambda 的版本可用,以便您可以使用:

    orderQuery.Include("Customer")
    

    orderQuery.Include(o => o.Customer)
    

    【讨论】:

    • 或使用 Microsoft.EntityFrameworkCore;如果是 .NET Core
    猜你喜欢
    • 1970-01-01
    • 2012-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-05
    • 2023-02-02
    相关资源
    最近更新 更多