示例#1
0
        public void Insert_with_explicit_non_default_keys()
        {
            using var testStore = SqlServerTestStore.CreateInitialized(DatabaseName);
            using (var context = new BlogContextNoKeyGeneration(testStore.Name))
            {
                context.Database.EnsureCreatedResiliently();

                context.AddRange(
                    new Blog {
                    Id = 66, Name = "One Unicorn"
                }, new Blog {
                    Id = 67, Name = "Two Unicorns"
                });

                context.SaveChanges();
            }

            using (var context = new BlogContextNoKeyGeneration(testStore.Name))
            {
                var blogs = context.Blogs.OrderBy(e => e.Id).ToList();

                Assert.Equal(66, blogs[0].Id);
                Assert.Equal(67, blogs[1].Id);
            }
        }
示例#2
0
    public void Insert_with_explicit_non_default_keys()
    {
        using (var context = new BlogContextNoKeyGeneration(nameof(Insert_with_explicit_non_default_keys)))
        {
            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();

            context.AddRange(
                new Blog {
                Id = 66, Name = "One Unicorn"
            }, new Blog {
                Id = 67, Name = "Two Unicorns"
            });

            context.SaveChanges();
        }

        using (var context = new BlogContextNoKeyGeneration(nameof(Insert_with_explicit_non_default_keys)))
        {
            var blogs = context.Blogs.OrderBy(e => e.Id).ToList();

            Assert.Equal(66, blogs[0].Id);
            Assert.Equal(67, blogs[1].Id);
        }
    }