Page 1 of 1

How to insert NULL Guid field?

Posted: Sun 07 Feb 2016 13:00
by Zero-G.
Hey

I use Entity Framework and I my tables are defined with Guid as Id field.
Now, I have in one table a Guid field, which is related to an other table, which can be 0 or one.
When I try to insert an empty field like:

Code: Select all

Table.GuidField = Guid.Empty
' Or
Table.GuidField = Nothing
The field get's a value of '00000000-0000-0000-0000-000000000000'
(Which is specific for Guid.Empty)
The Problem is, that I get an Foreign Key Error, because in the related table, there is no GUID record, which has this value (of Course there is no one)
But, how can I set this field to NULL?

THX

Re: How to insert NULL Guid field?

Posted: Tue 09 Feb 2016 14:14
by Shalex
Please set Nullable=True for the Guid field in your model. Now you can assign Nothing to it (or do not assign any value).