首页 文章

Linq-to-SQL外键是枚举

提问于
浏览
1

Linq-to-SQL任务 .

看图片 .

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

当我尝试实例化它时,我得到运行时异常'无法将null值赋给类型为XAccountId的成员,这是一个不可为空的值类型' . 当我将Type从XAccountId更改为int时 - 一切都按预期工作 . 为什么?我如何使用我的枚举作为键的类型?

附加:虽然我在属性窗口中设置Nullable = true,但生成的代码是 private XAccountId _AccountId1 = default(XAccountId); . 那么...... DBML生成器工作不正常?

附加2:http://social.msdn.microsoft.com/Forums/en-US/ee4f5703-570c-47bf-8003-bf15bd0f1441/map-nullable-enum与我的问题有关 . DBML生成器忽略枚举的CanBeNull = "true" .

1 回答

  • 1

    您可以将类型设置为 XAccountId? (带问号) . 正如错误所述,您不能将空值分配给值类型,只能分配给引用类型;和 enum 是值类型 . 另一种方法是让你的列不可为空 .

相关问题