views:

41

answers:

1

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)?

+2  A: 

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)
Craig Stuntz
Then why on earth are you using `Attach`?!? That makes almost no sense. What are you trying to accomplish by not just assigning the relationship directly: `Person.Address = ad`? I'll update my answer, but I feel like there must be something going on here which you haven't mentioned.
Craig Stuntz
Does the `DeleteObject` take care of the detaching too (i.e. setting null in the forgein's relation ID property)?
Shimmy
Not necessarily. Depends on whether it's a cascade. See this article: http://blogs.msdn.com/alexj/archive/2009/08/19/tip-33-how-cascade-delete-really-works-in-ef.aspx
Craig Stuntz