public void ShouldPerformMutlipleQueriesWhenRequested()
        {
            using (var context = new TestDbContext())
            {
                context.Set <OneToOneOneToOneAssociatedModel>().Add(_oneToOneAssociated);
                context.Set <OneToOneOneToManyAssociatedModel>().Add(_oneToManyAssociated);
                context.Nodes.Add(_node);
                context.SaveChanges();
            }

            var x          = new LocalDbConnectionFactory("v11.0");
            var connection = x.CreateConnection("GraphDiff");

            using (var context = new TestDbContext(connection))
            {
                // Setup mapping
                context.UpdateGraph(
                    entity: _node,
                    mapping: map => map.OwnedEntity(p => p.OneToOneOwned, with => with
                                                    .OwnedEntity(p => p.OneToOneOneToOneOwned)
                                                    .AssociatedEntity(p => p.OneToOneOneToOneAssociated)
                                                    .OwnedCollection(p => p.OneToOneOneToManyOwned)
                                                    .AssociatedCollection(p => p.OneToOneOneToManyAssociated)),
                    updateParams: new UpdateParams {
                    QueryMode = QueryMode.MultipleQuery
                });
            }

            // TODO how do I test number of queries..
        }
Esempio n. 2
0
        private static readonly Dictionary <string, DbCompiledModel> _compiledModels = new Dictionary <string, DbCompiledModel>(); // Farklı diller için oluşturulan DbCompiledModel'lerin tutulacağı dictionary

        static CompiledModels()
        {
            // Connection ve DbModelBuilder hazırlanıyor.
            var connectionFactory = new LocalDbConnectionFactory("DynamicMappingContext");
            var connection        = connectionFactory.CreateConnection("DynamicMappingContext");
            var builder           = new DbModelBuilder(DbModelBuilderVersion.V4_1);

            builder.Configurations.Add(new EntityTypeConfiguration <PersonBase>());

            // Türkçe için DbCompiledModel hazırlanıyor ve dictionary'ye ekleniyor.
            builder.Entity <Person>().ToTable("Person_TR");
            _compiledModels.Add("TR", builder.Build(connection).Compile());

            // İngilizce için DbCompiledModel hazırlanıyor ve dictionary'ye ekleniyor.
            builder.Entity <Person>().ToTable("Person_EN");
            _compiledModels.Add("EN", builder.Build(connection).Compile());
        }
Esempio n. 3
0
        public void Wipe_And_Create_Database()
        {
            var localDb          = new LocalDbConnectionFactory("MSSQLLocalDB");
            var connectionString = localDb.CreateConnection("CodeGolf.Sql.CodeGolfDbContext").ConnectionString;

            // drop database first
            ReallyDropDatabase(connectionString);

            // Now time to create the database from migrations
            // MyApp.Data.Migrations.Configuration is migration configuration class
            // this class is crated for you automatically when you enable migrations
            var initializer = new MigrateDatabaseToLatestVersion <CodeGolfDbContext, Migrations.Configuration>();

            // set DB initialiser to execute migrations
            Database.SetInitializer(initializer);

            // now actually force the initialisation to happen
            using (var domainContext = new CodeGolfDbContext(connectionString))
            {
                Console.WriteLine("Starting creating database");
                domainContext.Database.Initialize(true);
                Console.WriteLine("Database is created");
            }
        }