public void Attaching_previously_detached_entity_should_not_throw_exception() { using (var db = new DetachmentContext()) { var login = new DeLogin { Id = 14 }; var order = new DeOrder { Id = 19 }; login.Orders.Add(order); order.Login = login; db.Logins.Attach(login); ((IObjectContextAdapter)db).ObjectContext.Detach(login); Assert.Null(order.Login); db.Logins.Attach(login); Assert.Same(login, order.Login); Assert.True(login.Orders.Contains(order)); Assert.Equal(EntityState.Unchanged, db.Entry(login).State); Assert.Equal(EntityState.Unchanged, db.Entry(order).State); } }
public void Querying_for_previously_detached_entity_should_not_throw_exception() { using (var db = new DetachmentContext()) { var login = db.Logins.Include(l => l.Orders).First(); var order = login.Orders.First(); ((IObjectContextAdapter)db).ObjectContext.Detach(login); Assert.Null(order.Login); login = db.Logins.First(); Assert.Same(login, order.Login); Assert.True(login.Orders.Contains(order)); Assert.Equal(EntityState.Unchanged, db.Entry(login).State); Assert.Equal(EntityState.Unchanged, db.Entry(order).State); } }