Esempio n. 1
0
        [Fact] // Issue #931
        public async Task Can_save_and_query_with_schema()
        {
            var serviceProvider
                = new ServiceCollection()
                  .AddEntityFrameworkSqlServer()
                  .BuildServiceProvider();

            using (var testDatabase = await SqlServerTestStore.CreateScratchAsync())
            {
                await testDatabase.ExecuteNonQueryAsync("CREATE SCHEMA Apple");

                await testDatabase.ExecuteNonQueryAsync("CREATE TABLE Apple.Jack (MyKey int)");

                await testDatabase.ExecuteNonQueryAsync("CREATE TABLE Apple.Black (MyKey int)");

                using (var context = new SchemaContext(serviceProvider))
                {
                    context.Connection = testDatabase.Connection;

                    context.Add(new Jack {
                        MyKey = 1
                    });
                    context.Add(new Black {
                        MyKey = 2
                    });
                    context.SaveChanges();
                }

                using (var context = new SchemaContext(serviceProvider))
                {
                    context.Connection = testDatabase.Connection;

                    Assert.Equal(1, context.Jacks.Count());
                    Assert.Equal(1, context.Blacks.Count());
                }
            }
        }