Quantcast
Channel: Entity Framework
Viewing all articles
Browse latest Browse all 10318

Edited Feature: DbCollectionEntry should have Add, Remove, Attach methods [271]

$
0
0
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);


Viewing all articles
Browse latest Browse all 10318

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>