【问题标题】:List.Find throwing Nullable object must have a value errorList.Find 抛出 Nullable 对象必须有值错误
【发布时间】:2016-08-12 06:12:44
【问题描述】:
Dim sipff As SystemInfoPropertiesForForm = listSystemInfoPropertiesForForm.Find(Function(f) f.ShowFieldPropertyTypeId = CInt(SystemInfoPropertyIds.ShowMilestone))

SystemInfoPropertiesForForm 是一个复杂类型,所有项目都可以为空。

CInt(SystemInfoPropertyIds.ShowMilestone) = 900

listSystemInfoPropertiesForForm 有 10 项

有什么想法吗?

【问题讨论】:

  • 你的 .net 版本是什么?
  • f 是什么数据类型? f.ShowFieldPropertyTypeId 是什么数据类型? SystemInfoPropertyIds.ShowMilestone 是什么数据类型?
  • 我的 .Net 版本是 4.0。 “f”是列表“listSystemInfoPropertiesForForm”的别名。 f.ShowFieldPropertyTypeId 是整数,SystemInfoPropertyIds.ShowMilestone = string,类型转换为 int。它的值将是 900
  • 所以你想在对象列表(例如 listSystemInfoPropertiesForForm )中找到 ShowFieldPropertyTypeId=900 的 obj !?在这种情况下!?
  • Yes Cristic777..列表不为空,showfieldpropertytypeID 的值 = 900..但仍然出现错误

标签: asp.net vb.net entity-framework linq edmx


【解决方案1】:

使用下面的代码解决了这个问题

Dim sipff As SystemInfoPropertiesForForm = listSystemInfoPropertiesForForm.Find(Function(f) f.ShowFieldPropertyTypeId.HasValue AndAlso f.ShowFieldPropertyTypeId.Value = CInt(SystemInfoPropertyIds.ShowMilestone))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-13
    • 1970-01-01
    相关资源
    最近更新 更多