We have a pretty complex schema in Dynamics. A record has more than 150 OneToMany Relationships, 10 ManyToOne relationships, and 1 ManyToMany relationship.
I am trying to go through each relationship by executing this C# code which lives a WCF Service:
RetrieveEntityRequest retrieveCustomerRelationships = new RetrieveEntityRequest
{
EntityFilters = EntityFilters.Relationships,
LogicalName = "dummy_customer"
};
RetrieveEntityResponse customerRelationships = RetrieveEntityResponse)proxy.Execute(retrieveCustomerRelationships);
var oneToNRelationships = customerRelationships.EntityMetadata.OneToManyRelationships;
I'm iterating through each of the OneToMany relationships and trying to get the Id of the referenced entity. Depending on the entity type, i want to delete it. I thought i could use MetadataId as such:
foreach (var oneToNRelationship in oneToNRelationships){
RetrieveEntityRequest retrieveOneMetaDataRequest = new RetrieveEntityRequest
{
LogicalName = oneToNRelationship.SchemaName,
MetadataId = (Guid) oneToNRelationship.MetadataId
};
RetrieveEntityResponse oneMetadata = (RetrieveEntityResponse)proxy.Execute(retrieveOneMetaDataRequest);
}
But it is throwing a "Could not find entity error"
Does anyone have experience with MetadataId and how we can use it?
Thanks!
I was actually able to successfully delete this parent record by deleting all of the related records that were throwing errors in plugins. Still, I want to know how one can use MetadataId. Would appreciate if anyone could enlighten me.