예제 #1
0
        public void TransferDataFromMongoDbToSqlServer()
        {
            var mongoClient   = new MongoClient(MongoDbHost);
            var mongoDatabase = mongoClient.GetDatabase(MongoDbName);

            var hardDrivesMongoRepository    = new GenericMongoRepository <HardDriveMongoModel>(mongoDatabase);
            var memoriesMongoRepository      = new GenericMongoRepository <MemoryMongoModel>(mongoDatabase);
            var motherboardsMongoRepository  = new GenericMongoRepository <MotherboardMongoModel>(mongoDatabase);
            var processorsMongoRepository    = new GenericMongoRepository <ProcessorMongoModel>(mongoDatabase);
            var videoCardsMongoRepository    = new GenericMongoRepository <VideoCardMongoModel>(mongoDatabase);
            var computerShopsMongoRepository = new GenericMongoRepository <ComputerShopMongoModel>(mongoDatabase);
            var computersMongoRepository     = new GenericMongoRepository <ComputerMongoModel>(mongoDatabase);

            var hardDrivesRepository    = new GenericRepository <HardDrive>(dbContext);
            var memoriesRepository      = new GenericRepository <Memory>(dbContext);
            var motherboardsRepository  = new GenericRepository <Motherboard>(dbContext);
            var processorsRepository    = new GenericRepository <Processor>(dbContext);
            var videoCardsRepository    = new GenericRepository <VideoCard>(dbContext);
            var computerShopsRepository = new GenericRepository <ComputerShop>(dbContext);
            var computersRepository     = new GenericRepository <Computer>(dbContext);


            var migrator = new MongoToSqlMigrator();

            migrator.TransferHardDriveDataToSQL(hardDrivesRepository, hardDrivesMongoRepository);
            dbContext.SaveChanges();

            migrator.TransferMemoryDataToSQL(memoriesRepository, memoriesMongoRepository);
            dbContext.SaveChanges();

            migrator.TransferMotherboardDataToSQL(motherboardsRepository, motherboardsMongoRepository);
            dbContext.SaveChanges();

            migrator.TransferProcessorDataToSQL(processorsRepository, processorsMongoRepository);
            dbContext.SaveChanges();

            migrator.TransferVideoCardDataToSQL(videoCardsRepository, videoCardsMongoRepository);
            dbContext.SaveChanges();

            migrator.TransferComputerShopDataToSQL(computerShopsRepository, computerShopsMongoRepository);
            dbContext.SaveChanges();

            migrator.TransferComputerDataToSQL(hardDrivesRepository, memoriesRepository, motherboardsRepository, processorsRepository, videoCardsRepository, computerShopsRepository, computersRepository, computersMongoRepository);
            dbContext.SaveChanges();
        }
예제 #2
0
        public static void Main()
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion <ComputersFactoryDbContext, Configuration>());

            var dbContext = new ComputersFactoryDbContext();
            var worker    = new ComputersFactoryUnitOfWork(dbContext);

            var mongoClient   = new MongoClient(MongoDbHost);
            var mongoDatabase = mongoClient.GetDatabase(MongoDbName);

            var hardDrivesMongoRepository    = new GenericMongoRepository <HardDriveMongoModel>(mongoDatabase);
            var memoriesMongoRepository      = new GenericMongoRepository <MemoryMongoModel>(mongoDatabase);
            var motherboardsMongoRepository  = new GenericMongoRepository <MotherboardMongoModel>(mongoDatabase);
            var processorsMongoRepository    = new GenericMongoRepository <ProcessorMongoModel>(mongoDatabase);
            var videoCardsMongoRepository    = new GenericMongoRepository <VideoCardMongoModel>(mongoDatabase);
            var computerShopsMongoRepository = new GenericMongoRepository <ComputerShopMongoModel>(mongoDatabase);
            var computersMongoRepository     = new GenericMongoRepository <ComputerMongoModel>(mongoDatabase);

            var writer          = new MongoDbWriter();
            var randomGenerator = RandomGenerator.Create;

            writer.GenerateHardDrives(hardDrivesMongoRepository, randomGenerator);
            writer.GenerateMemories(memoriesMongoRepository, randomGenerator);
            writer.GenerateMotherboards(motherboardsMongoRepository, randomGenerator);
            writer.GenerateProcessors(processorsMongoRepository, randomGenerator);
            writer.GenerateVideoCards(videoCardsMongoRepository, randomGenerator);
            writer.GenerateComputerShops(computerShopsMongoRepository, randomGenerator);
            writer.GenerateComputers(hardDrivesMongoRepository, memoriesMongoRepository, motherboardsMongoRepository, processorsMongoRepository, videoCardsMongoRepository, computerShopsMongoRepository, computersMongoRepository, randomGenerator);

            var hardDrivesRepository    = new GenericRepository <HardDrive>(dbContext);
            var memoriesRepository      = new GenericRepository <Memory>(dbContext);
            var motherboardsRepository  = new GenericRepository <Motherboard>(dbContext);
            var processorsRepository    = new GenericRepository <Processor>(dbContext);
            var videoCardsRepository    = new GenericRepository <VideoCard>(dbContext);
            var computerShopsRepository = new GenericRepository <ComputerShop>(dbContext);
            var computersRepository     = new GenericRepository <Computer>(dbContext);


            var migrator = new MongoToSqlMigrator();

            migrator.TransferHardDriveDataToSQL(hardDrivesRepository, hardDrivesMongoRepository);
            RefreshContext(dbContext);

            migrator.TransferMemoryDataToSQL(memoriesRepository, memoriesMongoRepository);
            RefreshContext(dbContext);

            migrator.TransferMotherboardDataToSQL(motherboardsRepository, motherboardsMongoRepository);
            RefreshContext(dbContext);

            migrator.TransferProcessorDataToSQL(processorsRepository, processorsMongoRepository);
            RefreshContext(dbContext);

            migrator.TransferVideoCardDataToSQL(videoCardsRepository, videoCardsMongoRepository);
            RefreshContext(dbContext);

            migrator.TransferComputerShopDataToSQL(computerShopsRepository, computerShopsMongoRepository);
            RefreshContext(dbContext);

            migrator.TransferComputerDataToSQL(hardDrivesRepository, memoriesRepository, motherboardsRepository, processorsRepository, videoCardsRepository, computerShopsRepository, computersRepository, computersMongoRepository);
            RefreshContext(dbContext);
        }