示例#1
0
 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();
     }
 }
示例#2
0
 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();
     }
 }