实体框架.有限包含查询
本文关键字:包含 查询 框架 实体 | 更新日期: 2023-09-27 18:24:31
我有一个对象Customer
,它与Visit
具有one-to-many
关系。访问具有一定的VisitType
。
我想在某个日期后只取Visits
,这是我所有的Customers
。因此,我通过参数referenceDate
我能想到的Linq查询会给我想要的结果:
customers.Include(c => c.Visits.Where(v => v.VisitDate >= referenceDate)).ToList();
当然,这不起作用,因为Include
实际上需要一条路径。
对于这个问题,有Linq替代方案吗?或者我应该为此编写自定义查询吗?
也许你需要这样的东西:
customers.Include(c => c.Visits).Where(c => c.Visits.VisitDate >= referenceDate)).ToList();
或
customers.Include("Visits").Where(c => c.Visits.VisitDate >= referenceDate)).ToList();