Search code examples
entity-frameworkentity-relationshipnavigation-properties

Delete a relationship?


What is the opposite of:

Dim ad As New Address
Person.AddressReference.Attach(ad)

I mean how do I delete the Person.Address? (both with deleting and without - meaning only delete the relation)?


Solution

  • I don't do VB, so forgive me if my syntax isn't quite right.

    To "attach":

    Person.Address = ad
    

    To "detach"

    Person.Address = Nothing
    

    If you want to delete, then do:

    Context.DeleteObject(ad)