How to set null to a GUID property

后端 未结 8 1904
春和景丽
春和景丽 2020-12-16 10:25

I have an object of type Employee which has a Guid property. I know if I want to set to null I must to define my type property as nullable Nullable

8条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-16 10:44

    Choose your poison - if you can't change the type of the property to be nullable then you're going to have to use a "magic" value to represent NULL. Guid.Empty seems as good as any unless you have some specific reason for not wanting to use it. A second choice would be Guid.Parse("ffffffff-ffff-ffff-ffff-ffffffffffff") but that's a lot uglier IMHO.

提交回复
热议问题