Assign DateTime to Nullable <DateTime> in F #

I have F # code where I need to update a field in a database record. I am using Type Provider for SQL. The table has a field with a zero date value. When I try to update the value of a date field to DateTime.UtcNow, the compiler complains that "this expression should have been of type Nullable <DateTime>, but there is a DateTime type here." How to convert / distinguish from DateTime to Nullable <DateTime>.

My code currently looks something like this:

for queryItem in queryResult do queryItem.CurrentDate <- DateTime.UtcNow // This gives compiler error as described above 

Hello

+6
source share
1 answer

Comment by John Palmer over solution links. You need to use the constructor System.Nullable ie

 queryItem.CurrentDate <- System.Nullable DateTime.UtcNow 
+11
source

Source: https://habr.com/ru/post/947980/


All Articles