public void Query_dependent_include_principal_unidirectional_with_existing(EntityState existingState)
        {
            Seed();

            using var context = new QueryFixupContext();
            var newDependent = new ProductDN {
                CategoryId = 77
            };

            context.Entry(newDependent).State = existingState;

            var dependent = context.Set <ProductDN>().Include(e => e.Category).Single();
            var principal = dependent.Category;

            AssertFixup(
                context,
                () =>
            {
                Assert.Equal(principal.Id, dependent.CategoryId);
                Assert.Same(principal, dependent.Category);

                Assert.Equal(principal.Id, newDependent.CategoryId);
                Assert.Same(principal, newDependent.Category);
            });
        }
Пример #2
0
        public void Add_principal_then_dependent_one_to_many_dep_uni_FK_not_set_dependent_nav_set(EntityState entityState)
        {
            using (var context = new FixupContext())
            {
                var principal = new CategoryDN { Id = 77 };
                var dependent = new ProductDN { Id = 78, Category = principal };

                context.Entry(principal).State = entityState;
                context.Entry(dependent).State = entityState;

                Assert.Equal(principal.Id, dependent.CategoryId);
                Assert.Same(principal, dependent.Category);
                Assert.Equal(entityState, context.Entry(principal).State);
                Assert.Equal(entityState, context.Entry(dependent).State);
            }
        }
Пример #3
0
        public void Add_principal_but_not_dependent_one_to_many_dep_uni_FK_not_set_dependent_nav_set(EntityState entityState)
        {
            using (var context = new FixupContext())
            {
                var principal = new CategoryDN { Id = 77 };
                var dependent = new ProductDN { Id = 78 };

                context.Entry(principal).State = entityState;

                dependent.Category = principal;

                context.ChangeTracker.DetectChanges();

                AssertFixup(
                    context,
                    () =>
                        {
                            Assert.Equal(0, dependent.CategoryId);
                            Assert.Same(principal, dependent.Category);
                            Assert.Equal(entityState, context.Entry(principal).State);
                            Assert.Equal(EntityState.Detached, context.Entry(dependent).State);
                        });
            }
        }
Пример #4
0
        public void Add_principal_then_dependent_one_to_many_dep_uni_FK_set_no_navs_set(EntityState entityState)
        {
            using (var context = new FixupContext())
            {
                var principal = new CategoryDN { Id = 77 };
                var dependent = new ProductDN { Id = 78 };

                context.Entry(dependent).Property("CategoryId").CurrentValue = principal.Id;

                context.Entry(principal).State = entityState;
                context.Entry(dependent).State = entityState;

                AssertFixup(
                    context,
                    () =>
                        {
                            Assert.Equal(principal.Id, context.Entry(dependent).Property("CategoryId").CurrentValue);
                            Assert.Same(principal, dependent.Category);
                            Assert.Equal(entityState, context.Entry(principal).State);
                            Assert.Equal(entityState, context.Entry(dependent).State);
                        });
            }
        }
Пример #5
0
        public void Add_dependent_but_not_principal_one_to_many_dep_uni_FK_set_no_navs_set(EntityState entityState)
        {
            using (var context = new FixupContext())
            {
                var principal = new CategoryDN { Id = 77 };
                var dependent = new ProductDN { Id = 78 };

                context.Entry(dependent).State = entityState;

                dependent.CategoryId = principal.Id;

                context.ChangeTracker.DetectChanges();

                AssertFixup(
                    context,
                    () =>
                        {
                            Assert.Equal(principal.Id, dependent.CategoryId);
                            Assert.Null(dependent.Category);
                            Assert.Equal(EntityState.Detached, context.Entry(principal).State);
                            Assert.Equal(entityState == EntityState.Added ? EntityState.Added : EntityState.Modified, context.Entry(dependent).State);
                        });
            }
        }