I've created an assembly to use within a workflow in Dynamics 365 v9.
I have a Parent entity with a 1:N parental relationship to my Child entity. I want to create the Parent and Child in the same transaction so that if anything fails the whole thing is rolled back.
The documentation says this is done with the AddRelatedObject method.
var parent = new Parent()
{
Name = "PARENT"
};
var child = new Child()
{
Name = "CHILD"
};
crmContext.AddObject(parent);
crmContext.AddRelatedObject(parent, new Relationship("my_relationship"), child);
crmContext.SaveChanges();
The classes for Parent and Child were created with the Early Bound Generator plugin for XrmToolbox and have not been altered.
When I call SaveChanges
I get the exception:
Message: An error occured while processing this request.
Inner Message: Cannot find record to be updated
I don't know why this is occurring. The same code works in CRM 2011.
If I remove the AddRelatedObject
line the parent is created just fine.
Any ideas what I'm doing wrong?