I am afraid that 2.5 seconds to bind an object graph with 10,000 objects is "normal". This is probably a snapshot of the object that happens when you attach a graph that takes this time.
If βonly a small number usually changesβ - say, 100 - you could consider loading the source objects from the database and changing their properties instead of attaching the entire graph, for example:
using (var context = new MyEntities()) { // try with and without this line // context.Configuration.AutoDetectChangesEnabled = false; foreach (var child in myEntity.Children) { if (child.IsModified) { var childInDb = context.Children.Find(child.Id); context.Entry(childInDb).CurrentValues.SetValues(child); } //... etc. } //... etc. context.SaveChanges(); }
Despite the fact that this will create many queries to one database, only βflatβ objects without navigation properties that are connected (when calling Find ) will not consume much time will be downloaded and added. To reduce the number of requests, you can also try loading objects of the same type as the "package" using the Contains request:
var modifiedChildIds = myEntity.Children .Where(c => c.IsModified).Select(c => c.Id);
This is just a simplified example under the assumption that you only need to change the scalar properties of objects. It can become arbitrarily complex if changes in relationships are involved (children have been added and / or removed from collections, etc.).
source share