简体   繁体   English

使用控制台应用程序从2个不同的SQL Server数据库迁移数据

[英]Migrating data from 2 different SQL Server databases using console app

I have 2 web applications which are let's say Legacy1 and New1 . 我有2个Web应用程序,分别是Legacy1New1 I have separate DbContext for both applications and separate databases. 我对应用程序和数据库都有单独的DbContext

Now I want to migrate data from the Legacy1 database to the New1 database. 现在,我想将数据从Legacy1数据库迁移到New1数据库。 I cannot simply use copy database or export database options in SQL Server. 我不能在SQL Server中简单地使用copy databaseexport database选项。 Entities are different and I need to incorporate some logic while migrating data. 实体是不同的,在迁移数据时我需要合并一些逻辑。

I have decided to use .Net Core Console (.Net Framework) project to do this. 我决定使用.Net Core Console(.Net Framework)项目来执行此操作。 Do I have to add both DbContexts to this project? 我是否必须将两个DbContexts添加到该项目? Also all the entities which I want to map and do the migration or is there any other way to achieve this. 另外,我要映射并进行迁移的所有实体,或者是否有其他方法可以实现此目的。

Finally i found a simple approach to achieve that. 最终,我找到了一种简单的方法来实现这一目标。 I used EF DB First approach to generate edmx files for source and target databases. 我使用EF DB First方法为source数据库和target数据库生成edmx文件。 Which gives me access to corresponding Entities as well. 这也使我可以访问相应的Entities

I Queried source database using source dbcontext and manipulated data as per the requirements and inserted into target database using target dbcontext . 我使用源dbcontext源数据库,并根据要求处理数据,然后使用目标dbcontext将其插入目标数据库。 I used AutoMapper to map source entities to Target entities. 我使用AutoMappersource实体映射到Target实体。

It was much simpler than i thought earlier. 这比我以前想象的要简单得多。 Hope it helps others having similar scenario. 希望它可以帮助其他有类似情况的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用同步框架将数据从多个sql紧凑型数据库合并到中央sql服务器数据库的解决方案 - Solution for merging data from multiple sql compact databases to a central sql server database using sync framework 使用控制台应用程序从CSV到SQL Server批量数据插入 - Bulk Data insert from CSV to SQL Server using Console Application 将数据迁移到SQL Server 2008 - Migrating Data to SQL Server 2008 将数据从MongoDB迁移到SQL Server,性能会随着时间下降 - Migrating data from MongoDB to SQL Server, performance degrades over time 如何在C#控制台应用程序中使用XmlTextReader将XML数据插入SQL Server表中? - How to insert XML data into SQL Server table using XmlTextReader in C# console app? 在具有不同架构的不同sql服务器数据库中的表之间以编程方式复制数据 - Programmatically copying data across tables in different sql server databases having different schemas 将TFS数据迁移到SQL Server 2008进行报告 - migrating TFS data to SQL Server 2008 for reporting 从amazon SimpleDB迁移到SQL Server - Migrating from amazon SimpleDB to SQL Server 从Access迁移到SQL Server数据库 - Migrating from Access to SQL Server database 用c#在2个sql server数据库之间进行数据转换 - Data translation between 2 sql server databases with c #
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM