Пример #1
0
        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);
            }
        }
Пример #2
0
        protected override void Seed(DetachmentContext context)
        {
            var login = new DeLogin
            {
                Id         = 14,
                CustomerId = 21
            };
            var order = new DeOrder
            {
                Id = 19
            };
            var customer = new DeCustomer
            {
                DeCustomerId = 21
            };

            login.Orders.Add(order);
            order.Login    = login;
            login.Customer = customer;

            context.Logins.Add(login);
        }