How to run Entity framework migrations with data migration?

The bottom line is this: it was (and still exist) table workere (without right to logon to the server) and a few tables with users (managers and other management staff) and their roles that are created using ASP Net Identity. On worker tied several tables.

Now you need to transfer workerb to the table with users.

Use the EF Migration, with the help of automatically generated code for the migration, and in the middle of that code (after you created/updated the table and deleted table workername and others) are trying to make, in fact, the migration of data. I.e. (simplistically) something like this:
public override void Up()
 //Here is some code that updates the DB structure
 using (var db = new PCB())
 const string getWorkersCommand = "Select * from workers";
 var workers = db.Database.SqlQuery<worker>(getWorkersCommand);
 var userManager = new ApplicationUserManager(new UserStore<user>(db));
 var roleManager = new ApplicationRoleManager(new RoleStore<role>(db));

 foreach (var worker in workers)
 var newWorker = new User()
 var result = userManager.Create(newWorker);

 // Then for each created worker-living connection in linked tables

 //Here is some code that updates the DB structure</role></user></worker>

Actually, this doesn't work (which is expected), throws exception:
The basic model of context "CwDb" has changed since the database was created. Consider a database update by using Code First Migrations (

Sort of like the migrations has a special method, Sql(), but it does not return anything that could produce what I wrote above. Maybe I would write something in SQL and just do it via Sql(), but how users are generated in Asp.Net Identity is not clear, in particular Id, Legit Stamp.

In General, the question - how to do a proper data migration described in the case? I will be disappointed.
July 9th 19 at 10:54
2 answers
July 9th 19 at 10:56

Questions About Using EF
Questions about how to use the EF can be asked on Stack Overflow using the entity-framework tag.

EF Team
July 9th 19 at 10:58
a method of the DbMigrationsConfiguration.Seed is not suitable?
No, this method is invoked after migration, i.e., when all the old tables and fields removed.
In General, I came to the conclusion that using pure sql will migrate data, create users and roles. - Ayla_Braun commented on July 9th 19 at 11:01

Find more questions by tags .NETASP.NETEntity Framework