简体   繁体   中英

Linq-to-SQL foreign key is enum

Linq-to-SQL task.

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'. When I change Type from XAccountId to int - everything works as expected. 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); . So... DBML generator works incorrectly?

ADDITION 2: http://social.msdn.microsoft.com/Forums/en-US/ee4f5703-570c-47bf-8003-bf15bd0f1441/map-nullable-enum related to my problem. DBML generator ignores CanBeNull="true" for enums.

Can you set type to be XAccountId? (with question mark). As error says, you can't assign nulls to value types, only to reference types; and enum is a value type. The alternative is to make you column not nullable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM