【发布时间】:2015-07-09 20:47:29
【问题描述】:
我遇到了需要按日期和时间查询的情况。我正在尝试编写一个日期和时间格式相同的 EntityQuery。下面的查询不返回任何行。但是,如果我删除两个日期子句,则会返回行,然后我可以检查循环结果的日期。我更喜欢在查询中使用日期。
the variable ap in the query is a C# object
var query = from log in Manager.Logs
where log.StartDttm == ap.StartDttm
&& log.EndDttm == ap.EndDttm
&& log.TypeId == 1
select log;
我想出了这个解决方法来查询每个日期的午夜和晚上 11:59:59。我也不喜欢这样,但这至少会减少查询返回的行数。
var query = from log in Manager.Logs
where && log.StartDttm >= ap.StartDttmQueryBegin
&& log.StartDttm <= ap.StartDttmQueryEnd
&& log.EndDttm >= ap.EndDttmQueryBegin
&& log.EndDttm <= ap.EndDttmQueryEnd
&& log.TypeId == 1
select log;
【问题讨论】: