User1655654435 posted
Hi, I have an data that I need to migrate into a new database. The two databases have a slightly different structure(table relationships, some properties have been removied some added).
I'm at a loss to how i'm going to do it because the data is quite important. I've tried just opening the old database in sql object explorer and copy the rows, which did work for one table but not the rest because they got dependent relationships.
Mostly it's just two tables i need to copy. 1 is a TestResult table and the other is the Person table, linking those together (one Person can have many TestsResults).
I think the best way to do it would be to do it in code. So if I could just make a datacontext that had the same datamodels as the old one, I could just directly copy it into the new one making the changes as i put the data in the new. something like this:
var testResult = _oldContext.TestResult.Include(p => p.Person).ToList();
foreach(var item in TestResult)
{
var newTestResult = new newTestResult { Title = item.Title, ....etc }
_newContext.NewTestResult.Update(newTestResult);
}
_newContext.SaveChanges();
Allthough the names of the tables would be the same for the old and new tables, so I couldn't just make a variable to hold the data like that?
Maybe i'm just not thinking straight at the moment. Any help would be much apprechiated!