f# - 在 F# 中,表达式的类型应为“Nullable”' 但这里有类型 'DateTime'
问题描述
我在 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 是非空的,但访问定义将其设置为可空。因此,以下错误结果:
The expression was expected to have type
'Nullable<DateTime>'
but here has type
'DateTime'
如何在不更改数据库的情况下保持访问的定义相同并修复错误?
TIA
解决方案
您需要显式地创建一个Nullable
像这样的值:Nullable q.birthdate
.
推荐阅读
- mysql - SQL:选择表中特定字段集重复的所有条目
- oracle - 不同账户中的 Amazon RDS Oracle 数据库快照还原
- ruby-on-rails - 能够获得最小值,单个查询中的记录数
- kotlin - Is it safe to use Check and Require in production code? - Kotlin
- npm - 如何在未安装 cdk 时使用上下文参数执行 cdk 命令,即使用 npm run cdk?
- java - 将 Java HashMap 转换为海龟三元组
- python - mpdl3 和 lmfit 安装在终端中的 conda 成功,但在 spyder 中导入时未找到
- javascript - Number() 如果为 null 或为空,则默认为 0
- php - “分组” PHP 类的正确方法
- html - 将 div 放在两个 div 之间的边界之上