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(); } }
/// <summary> /// Create a new Contact object. /// </summary> /// <param name="id">Initial value of the Id property.</param> public static Contact CreateContact(global::System.Int32 id) { Contact contact = new Contact(); contact.Id = id; return contact; }
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(); } }
/// <summary> /// Deprecated Method for adding a new object to the ContactSet EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToContactSet(Contact contact) { base.AddObject("ContactSet", contact); }