1
votes

Linq-to-SQL task.

See pictures.

enter image description hereenter image description here

enter image description hereenter image description here

enter image description here

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.

1
It is still very unclear what's going on here. - Mike Perrenoud

1 Answers

1
votes

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.