c# - Relationship not set to null -


I have a very simple EF operation that fails: the relationship between the two entities as shown in the code below Break:

The database was generated earlier in the database. Institutions are defined as:

  Public Class Teacher {Public Entry ID (Receive; Set;} .. Public Virtual List & amp; Group & gt; Group {Receive; Set;}} public class group {public entry id (get; set;} .. public virtual teacher teacher {get; set;}}  

However, breaking relationships does not work , The teacher keeps pointing to the same unit. Step along with the debugger I see that teacher property is not created after zero. Teacher = Null I tried it with synchronous option, which had the same effect:

  Public Zero RemoveCurrentTeacherOfGroup (int groupId ) {Var group = _dataContext.Groups.Single (g = & gt; g.Id == group); group. Teacher = null; _dataContext.SaveChanges ();}  
< P>

If teacher is not loaded you can not link it either on query (curious load) Include:

  _dataContext.Groups.Include (g = & gt; G.Teacher). Single (G = & gt; GID == Group ID);  

Or if lazy loading is enabled, then use the property to read before clearing it:

  var teacher = group. teacher; group. Teacher = Null;  

You can see that " teacher is not zero after setting it to null " because the debugger reads the property After reaching (lazy after loading it) after setting it to null . Before

null already pressed the value group you did not load it before the Teacher = null line (if you load it If you see property value to empty the debugger before , if EF is actually loaded after idle loading is enabled after accessing the property to read) So it will work as expected and break the relationship, because sh Eccentrically will be loaded


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -