Example: a product entity is loaded including its tags without tracking:
repository.Product
.Include("Tag")
.Where(p => p.ProductID == 1)
.Execute(MergeOption.NoTracking);
Note that this is a many-to-many relationship; a product can have several tags, and tags can be associated with several products.
Somewhere else, I want to save any changes made to the product entity, but without saving changes made to its related tags or its relationship with these tags.
Meaning, neither of these changes may be saved:
- A tag has been removed from the product
- A tag has been added to the product
- A tag has been modified (e.g. name has been changed)
So I was thinking that I could somehow attach only the product to a new ObjectContext and save changes. But for some reason I can't figure out how to only attach a single entity to the object context, and not the entire graph.
Of course, I could attach the graph and then manually detach all other entities except the product in question, but this is a horrible solution, and I was hoping to find another.