我的理解是以下代码:
IQueryable<Things> things = dataContext.Things.Take(10);
if (fromDate > new DateTime(1980, 1, 1))
things = things.Where(a => a.InsertedDate > fromDate);
if (toDate < defaultDate)
things = things.Where(a => a.InsertedDate < toDate);
应该导致查询(假设日期通过条件),如:
select top 10 [fields] from things
where inserteddate > '1/8/2010'
and inserteddate < '1/12/2010'
我已经逐步完成并确认两个 Where() 语句正在设置,但是当我调用 things.ToList() 时,我得到了查询:
select top 10 [fields] from things
为什么没有将两个 where 合并到实际运行的查询中?