我在 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
Run Code Online (Sandbox Code Playgroud)
其中访问定义为:
type Visit = {
lastName : string
firstName : string
birthDate : Nullable<DateTime>
appointmentTime : Nullable<DateTime>
tservice : Nullable<DateTime>
postingTime : Nullable<DateTime>
chartNumber : Nullable<int>
}
Run Code Online (Sandbox Code Playgroud)
现在从数据库下载的 q.birthdate 是非空的,但访问定义将其设置为可以为空。因此,导致以下错误:
The expression was expected to have type
'Nullable<DateTime>'
but here has type
'DateTime'
Run Code Online (Sandbox Code Playgroud)
如何在不更改数据库的情况下保持 Visit 的定义不变并修复错误?
TIA