コード例 #1
0
        public void DetectChanges_can_be_called_twice_for_nullable_composite_key_with_related_entities()
        {
            ExtendedSqlAzureExecutionStrategy.ExecuteNew(
                () =>
            {
                using (var context = new BlogContext663())
                {
                    context.Configuration.AutoDetectChangesEnabled = false;
                    context.Database.Initialize(force: false);

                    using (context.Database.BeginTransaction())
                    {
                        var blog1 = context.CompositeBlogs.Add(new CompositeBlog663());
                        var blog2 = context.CompositeBlogs.Add(new CompositeBlog663());

                        blog1.Posts = new List <CompositePost663> {
                            new CompositePost663()
                        };
                        blog2.Posts = new List <CompositePost663> {
                            new CompositePost663()
                        };

                        context.ChangeTracker.DetectChanges();
                        context.ChangeTracker.DetectChanges();

                        Assert.Equal(EntityState.Added, context.Entry(blog1).State);
                        Assert.Equal(EntityState.Added, context.Entry(blog2).State);
                        Assert.Equal(EntityState.Added, context.Entry(blog1.Posts.First()).State);
                        Assert.Equal(EntityState.Added, context.Entry(blog2.Posts.First()).State);

                        blog1.Id1 = 1;
                        blog1.Id2 = 2;
                        blog2.Id1 = 1;
                        blog2.Id2 = 3;

                        context.ChangeTracker.DetectChanges();
                        context.SaveChanges();

                        Assert.Equal(EntityState.Unchanged, context.Entry(blog1).State);
                        Assert.Equal(EntityState.Unchanged, context.Entry(blog2).State);
                        Assert.Equal(EntityState.Unchanged, context.Entry(blog1.Posts.First()).State);
                        Assert.Equal(EntityState.Unchanged, context.Entry(blog2.Posts.First()).State);

                        Assert.NotNull(blog1.Id1);
                        Assert.NotNull(blog1.Id2);
                        Assert.NotNull(blog2.Id1);
                        Assert.NotNull(blog2.Id2);
                        Assert.Equal(blog1.Id1, blog1.Posts.First().BlogId1);
                        Assert.Equal(blog1.Id2, blog1.Posts.First().BlogId2);
                        Assert.Equal(blog2.Id1, blog2.Posts.First().BlogId1);
                        Assert.Equal(blog2.Id2, blog2.Posts.First().BlogId2);
                    }
                }
            });
        }
コード例 #2
0
        [Fact] // CodePlex 663
        public void DetectChanges_can_be_called_twice_for_nullable_key_with_related_entities()
        {
            using (var context = new BlogContext663())
            {
                context.Configuration.AutoDetectChangesEnabled = false;
                context.Database.Initialize(force: false);

                using (context.Database.BeginTransaction())
                {
                    var blog1 = context.Blogs.Add(new Blog663());
                    var blog2 = context.Blogs.Add(new Blog663());

                    blog1.Posts = new List <Post663> {
                        new Post663()
                    };
                    blog2.Posts = new List <Post663> {
                        new Post663()
                    };

                    context.ChangeTracker.DetectChanges();
                    context.ChangeTracker.DetectChanges();

                    Assert.Equal(EntityState.Added, context.Entry(blog1).State);
                    Assert.Equal(EntityState.Added, context.Entry(blog2).State);
                    Assert.Equal(EntityState.Added, context.Entry(blog1.Posts.First()).State);
                    Assert.Equal(EntityState.Added, context.Entry(blog2.Posts.First()).State);

                    context.SaveChanges();

                    Assert.Equal(EntityState.Unchanged, context.Entry(blog1).State);
                    Assert.Equal(EntityState.Unchanged, context.Entry(blog2).State);
                    Assert.Equal(EntityState.Unchanged, context.Entry(blog1.Posts.First()).State);
                    Assert.Equal(EntityState.Unchanged, context.Entry(blog2.Posts.First()).State);

                    Assert.NotNull(blog1.Id);
                    Assert.NotNull(blog2.Id);
                    Assert.Equal(blog1.Id, blog1.Posts.First().BlogId);
                    Assert.Equal(blog2.Id, blog2.Posts.First().BlogId);
                }
            }
        }
コード例 #3
0
        public void DetectChanges_can_be_called_twice_for_nullable_composite_key_with_related_entities()
        {
            using (var context = new BlogContext663())
            {
                context.Configuration.AutoDetectChangesEnabled = false;
                context.Database.Initialize(force: false);

                using (context.Database.BeginTransaction())
                {
                    var blog1 = context.CompositeBlogs.Add(new CompositeBlog663());
                    var blog2 = context.CompositeBlogs.Add(new CompositeBlog663());

                    blog1.Posts = new List<CompositePost663> { new CompositePost663() };
                    blog2.Posts = new List<CompositePost663> { new CompositePost663() };

                    context.ChangeTracker.DetectChanges();
                    context.ChangeTracker.DetectChanges();

                    Assert.Equal(EntityState.Added, context.Entry(blog1).State);
                    Assert.Equal(EntityState.Added, context.Entry(blog2).State);
                    Assert.Equal(EntityState.Added, context.Entry(blog1.Posts.First()).State);
                    Assert.Equal(EntityState.Added, context.Entry(blog2.Posts.First()).State);

                    blog1.Id1 = 1;
                    blog1.Id2 = 2;
                    blog2.Id1 = 1;
                    blog2.Id2 = 3;

                    context.ChangeTracker.DetectChanges();
                    context.SaveChanges();

                    Assert.Equal(EntityState.Unchanged, context.Entry(blog1).State);
                    Assert.Equal(EntityState.Unchanged, context.Entry(blog2).State);
                    Assert.Equal(EntityState.Unchanged, context.Entry(blog1.Posts.First()).State);
                    Assert.Equal(EntityState.Unchanged, context.Entry(blog2.Posts.First()).State);

                    Assert.NotNull(blog1.Id1);
                    Assert.NotNull(blog1.Id2);
                    Assert.NotNull(blog2.Id1);
                    Assert.NotNull(blog2.Id2);
                    Assert.Equal(blog1.Id1, blog1.Posts.First().BlogId1);
                    Assert.Equal(blog1.Id2, blog1.Posts.First().BlogId2);
                    Assert.Equal(blog2.Id1, blog2.Posts.First().BlogId1);
                    Assert.Equal(blog2.Id2, blog2.Posts.First().BlogId2);
                }
            }
        }
コード例 #4
0
        public void DetectChanges_can_be_called_twice_for_nullable_key_with_related_entities()
        {
            ExtendedSqlAzureExecutionStrategy.ExecuteNew(
                () =>
                {
                    using (var context = new BlogContext663())
                    {
                        context.Configuration.AutoDetectChangesEnabled = false;
                        context.Database.Initialize(force: false);

                        using (context.Database.BeginTransaction())
                        {
                            var blog1 = context.Blogs.Add(new Blog663());
                            var blog2 = context.Blogs.Add(new Blog663());

                            blog1.Posts = new List<Post663> { new Post663() };
                            blog2.Posts = new List<Post663> { new Post663() };

                            context.ChangeTracker.DetectChanges();
                            context.ChangeTracker.DetectChanges();

                            Assert.Equal(EntityState.Added, context.Entry(blog1).State);
                            Assert.Equal(EntityState.Added, context.Entry(blog2).State);
                            Assert.Equal(EntityState.Added, context.Entry(blog1.Posts.First()).State);
                            Assert.Equal(EntityState.Added, context.Entry(blog2.Posts.First()).State);

                            context.SaveChanges();

                            Assert.Equal(EntityState.Unchanged, context.Entry(blog1).State);
                            Assert.Equal(EntityState.Unchanged, context.Entry(blog2).State);
                            Assert.Equal(EntityState.Unchanged, context.Entry(blog1.Posts.First()).State);
                            Assert.Equal(EntityState.Unchanged, context.Entry(blog2.Posts.First()).State);

                            Assert.NotNull(blog1.Id);
                            Assert.NotNull(blog2.Id);
                            Assert.Equal(blog1.Id, blog1.Posts.First().BlogId);
                            Assert.Equal(blog2.Id, blog2.Posts.First().BlogId);
                        }
                    }
                });
        }