When I was writing the Unit test I got stuck at one point where I saw the code which will create 1:N relationships. But the problem was how to achieve that code in the unit test method? I searched everywhere but did not get a proper solution.
So in this blog, I am going to explain how to write a method for "EntityMetadata: OneToManyRelationshipMetadata".
SDK Reference
- using Microsoft.Xrm.Sdk.Metadata;
- RetrieveEntityRequest request = new RetrieveEntityRequest()
- {
- // Summary: EntityFilters is a ENUM where Relationships value is 8
- // Use this to retrieve entity information plus entity relationships for the entity.
- // Value = 8.
- EntityFilters = EntityFilters.Relationships,
- LogicalName = "account",
- RetrieveAsIfPublished = false,
- };
- RetrieveEntityResponse response = (RetrieveEntityResponse)service.Execute(request);
- if (response.EntityMetadata != null)
- {
- foreach (var relationships in response.EntityMetadata.OneToManyRelationships)
- {
- if (relationships.IsCustomizable.Value)
- {
- var referencingEntity = relationship.ReferencingEntity;
- var referencingAttribute = relationship.ReferencingAttribute;
- /*Your code to implement your logic*/
- ////
- ////
- }
- }
- }

Join the conversation! Your thoughts help the community grow.