I am loading a list of objects, need to map those objects and store it back to another database. Those two tables don't have the same schema, so a mapping is necessary.
For example:
using (var db1 = new Db1())
{
var customers = db1.CustomersDb1;
using (var db2 = new Db2())
{
foreach (var customer in customers)
{
var c = Mapper.Map<CustomerDb2>(customer);
db2.customers.Add(c);
}
db2.SaveChanges();
}
}
Now i tested this piece of code with round about 12000 entries and it lasted 2-3 minutes just until i reach db2.SaveChanges()
. So i even haven't stored anything after this time.
The Customer
object in Db2
just has 14 properties so i don't exactly know where it needs this much time.
Is there a faster way to map and copy two tables with Entity Framework
?
EDIT:
The most time is needed in the loop. So it's not a problem of the database. And it also doesn't matter if i use automapper
or if i map it manually.