Search code examples
c#sql-server-2012ef-code-first.net-coredbmigrate

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.


Solution

  • 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.