1

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.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Eric Han
  • 45
  • 2
  • 10

2 Answers2

0

this is not an answer, but an opportunity that may come in handy: "Delete Relationships To delete a relationship using the Web API, use the HTTP DELETE method with the URI for the relationship." https://learn.microsoft.com/en-us/powerapps/developer/common-data-service/webapi/create-update-entity-relationships-using-web-api

JUSTFUN
  • 5
  • 1
0

This error may occur when setting the related objects of the activity record in the target system. This is caused by the difference between the entity architecture names between the source Dynamics system and the target Dynamics system. For example, the entity architecture name of the target system is "mag_entityname", and the entity architecture name of the source system is "new_entityname".

You can refer to the links below, they all contain questions similar to yours:

Entity cannot be found error in Dynamics 365 for Outlook App

https://community.dynamics.com/crm/f/microsoft-dynamics-crm-forum/234651/web-application---could-not-find-entity/642165

Ding Peng
  • 3,702
  • 1
  • 5
  • 8