public void Manually_Remove_Reference() { using (var personsContext = new PersonsContext(DbContextOptions)) { var him = new Person { Id = 1, Name = "Him", SpouseId = 2 }; var her = new Person { Id = 2, Name = "Her", SpouseId = 1 }; personsContext.Persons.Add(him); personsContext.Persons.Add(her); personsContext.SaveChanges(); } using (var personsContext = new PersonsContext(DbContextOptions)) { var him = personsContext.Persons.Find(1); var her = personsContext.Persons.Find(2); him.SpouseId = null; personsContext.SaveChanges(); her.SpouseId = null; personsContext.SaveChanges(); personsContext.Persons.Remove(him); personsContext.SaveChanges(); } using (var personsContext = new PersonsContext(DbContextOptions)) { Assert.Null(personsContext.Find <Person>(1)); } }
public void OnDelete_SetNull() { using (var personsContext = new PersonsContext(DbContextOptions)) { var him = new Person { Id = 1, Name = "Him", SpouseId = 2 }; var her = new Person { Id = 2, Name = "Her", SpouseId = 1 }; personsContext.Persons.Add(him); personsContext.Persons.Add(her); personsContext.SaveChanges(); } using (var personsContext = new PersonsContext(DbContextOptions)) { var him = personsContext.Persons.Find(1); personsContext.Persons.Remove(him); personsContext.SaveChanges(); } using (var personsContext = new PersonsContext(DbContextOptions)) { Assert.Null(personsContext.Find <Person>(1)); } }