F#查询表达式 - 使用SQLite中的SqlProvider中的字符串比较进行限制

时间:2014-06-11 19:06:13

标签: sqlite f#

SQLite实际上没有日期列。您可以将日期存储为ISO-8601字符串,或者作为纪元以来的整数秒数,或者作为Julian日数。在我正在使用的表中,我希望我的日期是人类可读的,所以我选择使用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"))        
   ... }

我明白了:

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)
   ... }

我明白了:

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子句中进行字符串比较?似乎我在查询中过滤的唯一选择是在数据库中存储秒 - 自 - 纪元并使用整数比较。

1 个答案:

答案 0 :(得分:1)

这是旧SQLProvider版本的临时错误,它现在应该正常工作。如果没有,请在GitHub存储库中打开一个新问题:https://github.com/fsprojects/SQLProvider