For a particular user case, I want to manipulate a collection but prevent it from lazy loading. For Remove to have any effect, I have to do something like this:
db.Configuration.LazyLoadingEnabled = false;
((System.Data.Objects.DataClasses.IRelatedEnd)room.Users).Attach(user);
room.Users.Remove(user);
db.Configuration.LazyLoadingEnabled = true;
or even worse, if we cannot assume room is a change tracking proxy, then we have to do:
((IObjectContextAdapter)db).ObjectContext
.ObjectStateManager
.GetRelationshipManager(room)
.GetRelatedCollection<Users>(relationshipName, targetRoleName)
just to obtain the IRelatedEnd.
If DbCollectionEntry had Attach I could do someting like this:
db.Entry(room).Collection(r => r.Users).Attach(user);
db.Entry(room).Collection(r => r.Users).Remove(user);
db.Configuration.LazyLoadingEnabled = false;
((System.Data.Objects.DataClasses.IRelatedEnd)room.Users).Attach(user);
room.Users.Remove(user);
db.Configuration.LazyLoadingEnabled = true;
or even worse, if we cannot assume room is a change tracking proxy, then we have to do:
((IObjectContextAdapter)db).ObjectContext
.ObjectStateManager
.GetRelationshipManager(room)
.GetRelatedCollection<Users>(relationshipName, targetRoleName)
just to obtain the IRelatedEnd.
If DbCollectionEntry had Attach I could do someting like this:
db.Entry(room).Collection(r => r.Users).Attach(user);
db.Entry(room).Collection(r => r.Users).Remove(user);