Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Let’s say that Dave is no longer the primary contact for Dave’s
Dump. In fact, the service is so bad at this lodging that they no longer
have a contact at all. This means we simply want to remove the
relationship rather than changing it to a new Person.
To remove a relationship, you can remove the target object from a
collection navigation property. Alternatively, you can set a reference
navigation property to null. If your
classes expose a nullable foreign key property for the relationship, a
third option is to set the foreign key to null.
Removing relationships by changing the foreign key is only
possible with nullable properties (for example, the
PrimaryContactId property of the
Lodging class). If your foreign key is an int (for example, the
DestinationId property of the
Lodging class), you won’t be able to set the value
to null and by convention, that relationship would be required.
Setting the value to 0 would cause a primary key/foreign key
constraint error in the database, as there will be no parent whose
primary key is equal to 0.