c# - Entity Framework Delete Many to Many Relationship using stubs -


I am trying to remove many relationship entries between two entities, without asking any one of these first without first asking. Some on the lines of:

  phu fu = new foo () {id = 1}; Context.Foos.Attach (foo); Context.Entry (foo) .set = EntityState.Modified; Repeatedly = new times {id = 2}; Context.Bars.Attach (bar); Reference. Admission (bar) .set = EntityState.Modified; // This does not work: no exception, but the relationship was not deleted foo.Bars = new list & lt; Bar & gt; {times}; Foo.Bars.Remove (bar); Context.SaveChanges ();  

How can I remove times from foo? Bars relationships without first querying any unit?

You must have stub entities unchanged and in that regard Unchanged state (call accept all changes even after ) foo.Bars = new list & lt; Bar & gt; {times}; ). Only then foo.Bars.Remove (bar); deleted will relate to the state and SaveChanges will remove it. You can confirm what is happening by inspecting the underlying ObjectContext.ObjectStateManager - It contains dictionaries for institutions and relationships by their states. If you are not using a proxy then you may need Detachanges .


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

c# - Create dynamic LINQ query expression at runtime which translates into a parameterized SQL query for nullable types -

cmake - cpack generates RPMs with %files entries that conflict with the RPM spec. How to fix? -