How to set null to a GUID property

Is there a way to set my property as null or string.empty in order to restablish the field in the database as null.

No. Because it’s non-nullable. If you want it to be nullable, you have to use Nullable<Guid> – if you didn’t, there’d be no point in having Nullable<T> to start with. You’ve got a fundamental issue here – which you actually know, given your first paragraph. You’ve said, “I know if I want to achieve A, I must do B – but I want to achieve A without doing B.” That’s impossible by definition.

The closest you can get is to use one specific GUID to stand in for a null value – Guid.Empty (also available as default(Guid) where appropriate, e.g. for the default value of an optional parameter) being the obvious candidate, but one you’ve rejected for unspecified reasons.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)