Hello,
I have an entity A and a related entity B. The relationship is 1:N b/w A and B.
Plugin is run when update message is triggered for object of entity A. Now, i need to add some objects of entity type B and attach them to the object of entity A.
I am using organization service context - "unit of work pattern".
I have done something like following and it is successful:
Guid entityBid = setup.serviceUser.Create(objectB);
relations.Add(new EntityReference(A.EntityLogicalName, entityBid));
var relationship = new Relationship("relation_name");
setup.serviceUser.Associate("A_name", objectA.Id, relationship, relations);
But, this does not conform to the "unit of work pattern" principle, as i am using context to manage the transaction.
If any exception happens afterwards before serviceContext.saveChanges(), all dirty objects should NOT be saved to the server, but by using above method, i have actually saved the relationship to the server even if some exception occurs later.
Is there any general proposed way to do this by using context only?