How to insert NULL Guid field?

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
Posts: 391
Joined: Sat 09 Dec 2006 12:20

How to insert NULL Guid field?

Post by Zero-G. » Sun 07 Feb 2016 13:00


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?


Site Admin
Posts: 8247
Joined: Thu 14 Aug 2008 12:44

Re: How to insert NULL Guid field?

Post by Shalex » Tue 09 Feb 2016 14:14

Please set Nullable=True for the Guid field in your model. Now you can assign Nothing to it (or do not assign any value).

Post Reply