I have a Sql table with 12000 records and need to copy it to another table.
mset1 md = new mset1();
mset2 pd = new mset2();
foreach (var b in md.Myset) //dbset
{
Obj m = new Obj()
{
coslat = b.coslat,//float
Code = b.Code.Remove(b.Code.Length - 1),//string
sinlat = b.sinlat,//float
lat = b.lat,//float
lon = b.lon,//float
latrad = b.latrad,//float
lonrad = b.lonrad //float
};
pd.Postcodeset.Add(m);
pd.SaveChanges();
}
What I want to know when should I SaveChanges()
efficiently. Should it be inside the For
Loop or should it go outside the For
Loop.
Edit: I am worried because I have 7 floats
and the string Code
is on average 10kb each. If I dont save changes inside the For
Loop I might run out of memory.