setting a guid field to null

Posts   
 
    
mjcastillo
User
Posts: 10
Joined: 08-Feb-2007
# Posted on: 08-Feb-2007 06:11:57   

I have a field on one of my tables that is nullable. The type is uniqueindentifier (Guid). It is a foreign key to another table (so it 'points' to a uniqueidentifier field in another table). Since this field is nullable, that are times when I want to insert a record and not have a value in this field. The only way I can get this to compile and run is to have this field set to Guid.Empty. The problem with this is that when I insert the record, of course I get the foreign key violation because LLBL is inserting this record with a guid that has a value of "00000000....", and there is no record in the other table that is part of the foreign key relationship with that value. There has to be a way to set a Guid field to null. If I try and set it to DBNull.Value, I get an error saying it's not the right type. Any help would be greatly appreciated. Mike

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 08-Feb-2007 08:05:59   

Please check the section Entities, NULL values and defaults -> Setting a field to NULL in the LLBLGen Pro manual, under "Using the generated code -> Adapter/SelfServicing -> Using the entity classes"