[英]Linq-to-SQL foreign key is enum
Linq-to-SQL task. Linq-to-SQL任务。
See pictures. 看图片。
When I try to instantiate this, I get runtime exception 'The null value cannot be assigned to a member with type XAccountId which is a non-nullable value type'. 当我尝试实例化它时,我收到运行时异常“无法将空值分配给XAccountId类型的成员,该类型是非空值类型”。 When I change Type from XAccountId to int - everything works as expected.
当我将类型从XAccountId更改为int时,一切都会按预期进行。 Why?
为什么? How I can use my enum as Type of keys?
如何将枚举用作键的类型?
ADDITION: Although I set Nullable = true in property window, generated code is private XAccountId _AccountId1 = default(XAccountId);
补充:尽管我在属性窗口中将Nullable设置为true,但是生成的代码是
private XAccountId _AccountId1 = default(XAccountId);
. 。 So... DBML generator works incorrectly?
那么... DBML生成器无法正常工作?
ADDITION 2: http://social.msdn.microsoft.com/Forums/en-US/ee4f5703-570c-47bf-8003-bf15bd0f1441/map-nullable-enum related to my problem. 补充2: http : //social.msdn.microsoft.com/Forums/en-US/ee4f5703-570c-47bf-8003-bf15bd0f1441/map-nullable-enum与我的问题有关。 DBML generator ignores CanBeNull="true" for enums.
DBML生成器会忽略CanBeNull =“ true”的枚举。
Can you set type to be XAccountId?
您可以将type设置为
XAccountId?
(with question mark). (带问号)。 As error says, you can't assign nulls to value types, only to reference types;
正如错误所言,您不能将null分配给值类型,而只能分配给引用类型。 and
enum
is a value type. enum
是一个值类型。 The alternative is to make you column not nullable. 替代方法是使您的列不可为空。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.