简体   繁体   中英

Entity framework changes property value to null when adding unrelated entity

In one of my files, I add a new entity to my context like this:

_contex.Documents.Add(NewDocument)

Then for some reason, another entity gets a property set to null. The other entity is related to the NewDocument through a many-to-many-entity, but is not functionality related in any other way.

The stack trace for the setting of null looks like this: this , where the first row is were null is set, the last is where I add the document and all the middle ones are gray, ie not loaded in the debugger.

Does anyone know why this happens? It doesn't seem to affect any other property value.

Is it possible that your Document NewDocument has a navigation property ( virtual list ) of your other object, but does not contain the other object inside its list, and EF thinking that they have become unrelated.

Could you please post the 2 classes in questions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM