我有一些F#代码,我需要更新数据库记录中的字段。我正在使用Type Provider for SQL。该表具有可空的日期值字段。当我尝试将date字段的值更新为DateTime.UtcNow时,编译器会抱怨“此表达式应该具有Nullable类型< DateTime>但这里的类型为DateTime”。如何将DateTime转换/转换为Nullable< DateTime>。
我的代码目前看起来如下:
for queryItem in queryResult do
queryItem.CurrentDate <- DateTime.UtcNow // This gives compiler error as described above
此致
答案 0 :(得分:13)
John Palmer的评论上面是解决方案的链接。需要使用System.Nullable构造函数,即
queryItem.CurrentDate <- System.Nullable DateTime.UtcNow