需要帮助尝试在 EntityFramework 中 EagerLoad 一些数据
我正在尝试对 EF 实体进行一些预先加载。
所以,如果实体名为 Orders
.. 那么我想我会执行以下操作...
_someContext.Orders.Include("Whatever") ....
但是问题是,我有一个像下面这样的方法...
public IQueryable<Order> Find(Expression<Func<Order, bool>> predicate)
{
return CurrentContext.Orders.Where(predicate);
}
效果很好..但是我可以利用 Expression
谓词将 Include("whatever")
包含在那里,而不必添加另一个方法参数?
I'm trying to do some eager loading on an EF Entity.
so, if the entity is called Orders
.. then I guess i would do the following...
_someContext.Orders.Include("Whatever") ....
But the problem is, I have a method like the following ...
public IQueryable<Order> Find(Expression<Func<Order, bool>> predicate)
{
return CurrentContext.Orders.Where(predicate);
}
which works great .. but can i leverage the Expression
predicate to include the Include("whatever")
in there, instead of having to add another method parameter?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不这么认为。由于谓词和 ObjectQuery.Where 方法 一般来说,与 Include 的急切加载无关。虽然您可以创建一个扩展方法,但这并不能避免您使用另一个参数来指定包含:
I don't think so. Since the predicate and ObjectQuery.Where Method in genral has nothing to do with eager loading by Include. You can create a extension method though, but that does not save you from having yet another parameter for specifying the include: