Cannot insert multiple objects without calling SaveChanges() every time
I'm trying to add several objects to the DB with EF ObjectContext without
calling the SaveChanges() after each add. Problem is, that only the last
added object is committed to the DB.
using (var entities = new ModelEntities())
{
foreach (service in services)
{
entities.Services.AddObject(service);
}
entities.SaveChanges();
}
When I call the SaveChanges() method directly after AddObject all objects
are inserted but performance is affected. What am I doing wrong?
Thanks.
No comments:
Post a Comment