简体   繁体   中英

Migrating data from 2 different SQL Server databases using console app

I have 2 web applications which are let's say Legacy1 and New1 . I have separate DbContext for both applications and separate databases.

Now I want to migrate data from the Legacy1 database to the New1 database. I cannot simply use copy database or export database options in SQL Server. 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. Do I have to add both DbContexts to this project? 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. Which gives me access to corresponding Entities as well.

I Queried source database using source dbcontext and manipulated data as per the requirements and inserted into target database using target dbcontext . I used AutoMapper to map source entities to Target entities.

It was much simpler than i thought earlier. Hope it helps others having similar scenario.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM