8

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

像,

this.repository.GetQuery<GeneralCalendarDates>()

这没有包含方法,尽管我可以在这里使用 .ToList() 。

知道这里可能有什么问题吗?

4

1 回答 1

25

Includefor是在程序集IQueryable<T>的命名空间中实现的扩展方法。所以你的项目必须引用这个程序集,你必须添加System.Data.EntityEntityFramework.dll

using System.Data.Entity;

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

orderQuery.Include("Customer")

或者

orderQuery.Include(o => o.Customer)
于 2013-03-02T15:03:40.513 回答