Hi Tomas,
Calling Add will already add the graph of objects reachable from the entity passed to Add. The traversal of the graph stops when an entity already tracked by the context is encountered. However, if a tracked entity references a new entity, then it will be picked up automatically when DetectChanges is called, either implicitly by using one of the methods of the context (such as Add) or explicitly.
When you say "update entity B" I'm not sure exactly what you mean. Do you mean that the graph being added contains an object with the same key and another object that is already being tracked and that the tracked object should be updated from the untracked object with the same key? or is there just one object B here which is being tracked by the context already? If it is the former, then this is an interesting scenario, although defining the behavior around relationships between multiple objects with the same keys is non-trivial. If it is the latter, then can you explain more of what you mean by "update entity B"?
Thanks,
Arthur
Calling Add will already add the graph of objects reachable from the entity passed to Add. The traversal of the graph stops when an entity already tracked by the context is encountered. However, if a tracked entity references a new entity, then it will be picked up automatically when DetectChanges is called, either implicitly by using one of the methods of the context (such as Add) or explicitly.
When you say "update entity B" I'm not sure exactly what you mean. Do you mean that the graph being added contains an object with the same key and another object that is already being tracked and that the tracked object should be updated from the untracked object with the same key? or is there just one object B here which is being tracked by the context already? If it is the former, then this is an interesting scenario, although defining the behavior around relationships between multiple objects with the same keys is non-trivial. If it is the latter, then can you explain more of what you mean by "update entity B"?
Thanks,
Arthur