public void ContactHasOneOrZeroAddresses_AddressHasOneContact_WithEF() { using (new TransactionScope()) { var entities = new Entities(); var contact = new Contact{Name = "Test"}; contact.Address = new Address {Street = "Lipowa"}; entities.AddToContactSet(contact); entities.SaveChanges(); List<Contact> contacts = entities.ContactSet.Where(x=>x.Name == "Test").ToList(); entities.DeleteObject(contacts[0].Address); contacts[0].Address = null; entities.SaveChanges(); } }
public void WhenRemovingContactShouldAlsoRemoveReferencedAddress_withEF() { using (new TransactionScope()) { var contact = new Contact {Name = "Test", Address = new Address {Street = "Lipowa"}}; var entities = new Entities(); entities.AddToContactSet(contact); entities.SaveChanges(); entities.DeleteObject(contact); entities.SaveChanges(); } }