在我的EF实现通用存储库中找不到.Include()方法 [英] Not finding .Include() method in my EF implementing Generic repository

查看:242
本文介绍了在我的EF实现通用存储库中找不到.Include()方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using Generic repository to wrap DbContext and DbSet classes from upper level. However, when in certain queries I need to use ".Include()" method to include navigation properties. But I am unable to find these methods on repository methods returing IQueryable

this.repository.GetQuery<GeneralCalendarDates>()

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

this doesn't have include method, though I can use .ToList() here.

任何人在这里可能会出错吗?

Any idea what could be wrong here?

推荐答案

Include for IQueryable< T> 是在命名空间中实现的扩展方法程序集 EntityFramework.dll 中的 System.Data.Entity 。因此,您的项目必须引用该程序集,并且必须使用System.Data.Entity添加

Include for IQueryable<T> is an extension method that is implemented in namespace System.Data.Entity in the assembly EntityFramework.dll. So your project must reference this assembly and you must add

using System.Data.Entity;

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

at the beginning of your code file. It will make the string and lambda based version of Include available, so that you can use:

orderQuery.Include("Customer")

orderQuery.Include(o => o.Customer)

这篇关于在我的EF实现通用存储库中找不到.Include()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆