public IList <SalesReport> ImportSalesReportsFromExcel(string fileName, string tempFileName) { if (string.IsNullOrEmpty(fileName)) { fileName = SqlServerExcelSalesReportsImporter.DefaultFileName; } if (string.IsNullOrEmpty(tempFileName)) { tempFileName = SqlServerExcelSalesReportsImporter.DefaultTempFileName; } var reports = this.dataParser.ParseCompressedExcelData(fileName, tempFileName); var reportsCount = 0; foreach (var report in reports) { reportsCount++; context.SalesReports.Add(report); if (reportsCount % 100 == 0) { context.SaveChanges(); } } context.SaveChanges(); return(reports.ToList()); }
public IList <SalesReport> ImportData(string fileName, string rootElement) { if (string.IsNullOrEmpty(fileName)) { throw new ArgumentNullException(nameof(fileName)); } if (string.IsNullOrEmpty(rootElement)) { throw new ArgumentNullException(nameof(rootElement)); } var salesReportsFromXml = this.xmlDeserializer.DeserializeXmlToIListOf <XmlSalesReport>(fileName, rootElement); var salesReportsWithoutNestedCollection = this.modelConverter.ConvertToIList <XmlSalesReport, SalesReport>(salesReportsFromXml); var createdReports = new List <SalesReport>(); var reportsCount = salesReportsFromXml.Count; for (int reportIndex = 0; reportIndex < reportsCount; reportIndex++) { var importedReport = salesReportsFromXml[reportIndex]; var exportedReport = salesReportsWithoutNestedCollection[reportIndex]; var sales = this.modelConverter.ConvertToIList <XmlSale, Sale>(importedReport.Sales); exportedReport.Sales = sales; this.context.SalesReports.Add(exportedReport); createdReports.Add(exportedReport); if (reportIndex % 100 == 99) { context.SaveChanges(); } } context.SaveChanges(); return(createdReports); }
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(); }