I am updating child entities in the pre-operation of Update message.
Parent Entity - salesorder
Child entity - salesorderdetail
code snippet here:
List lineEntitesToUpdate = new List(); foreach (Entity lineEntity in ec.Entities) { lineEntity["tax"] = new Money(9.5); //other custom settings update lineEntitiesToUpdate.Add(lineEntity); } orderFromContext.RelatedEntities.Add(new Relationship("order_details"), new EntityCollection(lineEntitiesToUpdate));
orderFromContext is the entity obtained from context.
ec is the entitycollection of related salesorderdetail
Reason i am not using service.Update(lineEntity); is because when 1st line item is updated that calls parent update and it messes up rest of the line items
Problem:
Last line in the code does update the related child entities only once, subsequent updates it wont change anything for child entities. I even don't know why it updates only once and when it decides to update once. There no pattern to it that lines are updated only after creation on line items, it seems random. I don't know why it update only once and not subsequent once.
note: I am not using service.Update(orderFromContext); because my plugin is registered on pre-operation of Update
Please let me know if you need any more information. I followed this link for relatedentities https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/org-service/entity-operations-update-delete