예제 #1
0
        public void Setting_IsModified_false_reverts_changes_to_join_table_FKs()
        {
            using var context = new ExplicitFreezerContext();

            var cherry1 = new Cherry {
                Id = 1
            };
            var cherry2 = new Cherry {
                Id = 2
            };
            var chunky1 = new Chunky {
                Id = 1
            };
            var chunky2 = new Chunky {
                Id = 2
            };

            AttachGraph(context, cherry1, cherry2, chunky1, chunky2);

            var relatedToCherry1 = context.Entry(cherry1).Collection(e => e.Chunkies);
            var relatedToCherry2 = context.Entry(cherry2).Collection(e => e.Chunkies);
            var relatedToChunky1 = context.Entry(chunky1).Collection(e => e.Cherries);
            var relatedToChunky2 = context.Entry(chunky2).Collection(e => e.Cherries);

            var joinEntity = context.ChangeTracker.Entries <Dictionary <string, object> >()
                             .Single(e => e.Property <int>("CherryId").CurrentValue == 1 && e.Property <int>("ChunkyId").CurrentValue == 2)
                             .Entity;

            joinEntity["CherryId"] = 2;
            context.ChangeTracker.DetectChanges();

            Assert.False(relatedToCherry1.IsModified);
            Assert.True(relatedToCherry2.IsModified);
            Assert.False(relatedToChunky1.IsModified);
            Assert.True(relatedToChunky2.IsModified);

            relatedToCherry2.IsModified = false;

            Assert.False(relatedToCherry1.IsModified);
            Assert.False(relatedToCherry2.IsModified);
            Assert.False(relatedToChunky1.IsModified);
            Assert.False(relatedToChunky2.IsModified);

            foreach (var joinEntry in context.ChangeTracker.Entries <Dictionary <string, object> >())
            {
                Assert.Equal(EntityState.Unchanged, joinEntry.State);
            }
        }
예제 #2
0
        public void Setting_IsModified_true_marks_all_join_table_FK_modified()
        {
            using var context = new ExplicitFreezerContext();

            var cherry1 = new Cherry {
                Id = 1
            };
            var cherry2 = new Cherry {
                Id = 2
            };
            var chunky1 = new Chunky {
                Id = 1
            };
            var chunky2 = new Chunky {
                Id = 2
            };

            AttachGraph(context, cherry1, cherry2, chunky1, chunky2);

            var relatedToCherry1 = context.Entry(cherry1).Collection(e => e.Chunkies);
            var relatedToCherry2 = context.Entry(cherry2).Collection(e => e.Chunkies);
            var relatedToChunky1 = context.Entry(chunky1).Collection(e => e.Cherries);
            var relatedToChunky2 = context.Entry(chunky2).Collection(e => e.Cherries);

            Assert.False(relatedToCherry1.IsModified);
            Assert.False(relatedToCherry2.IsModified);
            Assert.False(relatedToChunky1.IsModified);
            Assert.False(relatedToChunky2.IsModified);

            foreach (var joinEntry in context.ChangeTracker.Entries <Dictionary <string, object> >())
            {
                Assert.Equal(EntityState.Unchanged, joinEntry.State);
            }

            relatedToCherry1.IsModified = true;

            Assert.True(relatedToCherry1.IsModified);
            Assert.False(relatedToCherry2.IsModified);
            Assert.True(relatedToChunky1.IsModified);
            Assert.True(relatedToChunky2.IsModified);

            foreach (var joinEntry in context.ChangeTracker.Entries <Dictionary <string, object> >())
            {
                Assert.Equal(EntityState.Modified, joinEntry.State);
            }
        }
예제 #3
0
        public void IsModified_tracks_mutation_of_join_fks()
        {
            using var context = new ExplicitFreezerContext();

            var cherry1 = new Cherry {
                Id = 1
            };
            var cherry2 = new Cherry {
                Id = 2
            };
            var chunky1 = new Chunky {
                Id = 1
            };
            var chunky2 = new Chunky {
                Id = 2
            };

            AttachGraph(context, cherry1, cherry2, chunky1, chunky2);

            var relatedToCherry1 = context.Entry(cherry1).Collection(e => e.Chunkies);
            var relatedToCherry2 = context.Entry(cherry2).Collection(e => e.Chunkies);
            var relatedToChunky1 = context.Entry(chunky1).Collection(e => e.Cherries);
            var relatedToChunky2 = context.Entry(chunky2).Collection(e => e.Cherries);

            var joinEntity = context.ChangeTracker.Entries <Dictionary <string, object> >()
                             .Single(e => e.Property <int>("CherryId").CurrentValue == 1 && e.Property <int>("ChunkyId").CurrentValue == 2)
                             .Entity;

            joinEntity["CherryId"] = 2;
            context.ChangeTracker.DetectChanges();

            Assert.False(relatedToCherry1.IsModified);
            Assert.True(relatedToCherry2.IsModified);
            Assert.False(relatedToChunky1.IsModified);
            Assert.True(relatedToChunky2.IsModified);

            joinEntity["CherryId"] = 1;
            context.ChangeTracker.DetectChanges();

            Assert.True(relatedToCherry1.IsModified);
            Assert.False(relatedToCherry2.IsModified);
            Assert.False(relatedToChunky1.IsModified);
            Assert.True(relatedToChunky2.IsModified);
        }