SQLite并没有真正的日期列。您可以将日期存储为ISO-8601字符串,或者作为自纪元以来的秒数的整数,或者作为朱利安日号码。在我使用的表中,我希望我的日期是人类可读的,因此我选择使用ISO-8601字符串。
假设我想查询今天之后的所有记录。ISO-8601字符串将正确排序,所以我应该能够使用与今天日期的ISO-8601字符串进行字符串比较。
然而,我没有看到使用F# SqlProvider类型提供程序进行比较的方法。我希望这只是反映了我对F#查询表达式的了解不足。
例如,我不能执行以下操作:
query {
for calendarEntry in dataContext.``[main].[calendar_entries]`` do
where (calendarEntry.date >= System.DateTime.Today.ToString("yyyy-MM-dd hh:mm:ss"))
... }
I get:
The binary operator GreaterThanOrEqual is not defined for the types 'System.String' and 'System.String'.
我也不能执行任何变体:
query {
for calendarEntry in dataContext.``[main].[calendar_entries]`` do
where (calendarEntry.date.CompareTo(System.DateTime.Today.ToString("yyyy-MM-dd hh:mm:ss")) >= 0)
... }
I get:
Unsupported expression. Ensure all server-side objects appear on the left hand side of predicates. The In and Not In operators only support the inline array syntax.
有人知道我如何在where子句中进行字符串比较吗?似乎我的唯一过滤查询内部的选项是将自纪元以来的秒数存储在数据库中并使用整数比较。