我在F#中有以下函数,它从本地数据库返回数据:
let GetScheduleAsync (tableDate : DateTime) =
async {
let! data = context.GetOfficeScheduleAsync(tableDate) |> Async.AwaitTask
return data |> Seq.map(fun q -> {
Visit.lastName = q.lastname
firstName = q.firstname
birthDate = q.birthdate
appointmentTime = q.appointment_time
tservice = q.service_time
postingTime = q.posting_time
chartNumber = q.chart_number
})
}
|> Async.StartAsTask
访问定义为:
type Visit = {
lastName : string
firstName : string
birthDate : Nullable<DateTime>
appointmentTime : Nullable<DateTime>
tservice : Nullable<DateTime>
postingTime : Nullable<DateTime>
chartNumber : Nullable<int>
}
现在,从数据库下载的q.birthdate是非null的,但Visit定义将其设为null。因此,出现以下错误:
The expression was expected to have type
'Nullable<DateTime>'
but here has type
'DateTime'
如何在不更改数据库并修复错误的情况下保持Visit的定义不变?
TIA-
您需要显式生成Nullable
值,如下所示:Nullable q.birthdate
。