i need to update 100 records on a single button click using entity framework 4.1 (POCO). I need to save the modified records in the database without doing database roundtrip (to avoid performance issue).
I have seen some solution with detach and attach.
getting error on attach An entity object cannot be referenced by multiple instances of IEntityChangeTracker
so tried detach first, get the new error The object cannot be detached because it is not attached to the ObjectStateManager
i am using repository pattern to get list of entities and passing to UI layer for binding in the grid.
in the button click, I am passing these entities back DB layer to update.
it works fine, with select the entity and do the context.applychanges. I need to avoid this round trip, for performance issue.
public void Update(OPRPortCall portCall)
{
using (VMEntities context = new VMEntities())
{
context.Detach(portCall); //The object cannot be detached because it is not attached to the ObjectStateManager.
context.AttachTo("OPRPortCalls", portCall); //An entity object cannot be referenced by multiple instances of IEntityChangeTracker
context.ObjectStateManager.ChangeObjectState(portCall, EntityState.Modified);
context.SaveChanges();
}
}
advise me any solution for this.
christopher