实体框架。限制包括查询

时间:2014-09-26 09:14:28

标签: c# linq entity-framework

我有一个与Customerone-to-many关系的对象Visit。 访问有一定的VisitType

我想在特定日期之后仅提取Visits,而我只需要Customers。因此,我传递参数referenceDate

Linq查询我能想到这会给我想要的结果:

customers.Include(c => c.Visits.Where(v => v.VisitDate >= referenceDate)).ToList();

由于Include实际上需要一条路径,所以这不起作用。

是否有Linq替代此问题,还是应该为此编写自定义查询?

1 个答案:

答案 0 :(得分:0)

也许你需要这样的东西:

customers.Include(c => c.Visits).Where(c => c.Visits.VisitDate >= referenceDate)).ToList();

customers.Include("Visits").Where(c => c.Visits.VisitDate >= referenceDate)).ToList();

相关问题