Remove a foreign key ID from an entity

Posts   
 
    
Posts: 116
Joined: 18-Feb-2006
# Posted on: 29-May-2006 01:30:26   

I have a LocationEntity that has a nullable foreign key to a RegionEntity.

If I wanted to remove the value in the RegionID field, how can I do that?

Dim objLocation as New LocationEntity(200)
objLocation.RegionID = Nothing 
objLocation.Save()

The above code does not work and is giving me a Foreign Key constraint error.

Posts: 116
Joined: 18-Feb-2006
# Posted on: 29-May-2006 03:13:51   

I found the solution. I had to add the following code to my business layer

If objLocation.RegionId = 0 Then
    objLocation.SetNewFieldValue(CType(LocationFieldIndex.RegionId, Integer), Nothing)
End If