I have two different databases that have a table each with the same exact structure. I would like to upload the registers retrieved from DB1 into DB2. I tried some methods using the same entity or converting it to a List object, as follows. The list of the registers from DB1 is generated properly, but how to insert it into DB2?
object pendingRowsList = new object();
//Get registers from DB1
using (var context = new DB1())
{
pendingRowsList = context.table_local.OrderByDescending(x =>
x.id).Take(numberOfRows).ToList();
}
//Upload registers into DB2
using (var context = new DB2())
{
for (int i = numberOfRows; i > 0; i--)
{
var newDbRow = new table_remote(pendingRowsList[i]); //that is what I am trying to achieve
context.table_remote.Add(newDbRow);
context.SaveChanges();
}
}