C# Console to Get Dynamics CRM Relationship Metadata
Updated: May 18, 2020
Long story short. I am working for a client whom uses shares as part of the security model in Dynamics CRM (this is not advisable, but its the design we have inherited).
There is a concern that ghost shares could be created. Ghost shares are created by relationships configured with cascade share.
I have created a .NET console that extracts all relationship metadata to excel. The source code can be downloaded here.
The application uses the Xrm Tooling assemblies.
Below is an example of a contact to lead relationship that has been set up with cascading shares and the corresponding output of the console application.
The Visual Studio Solution:
VS Project Properites
Uses Visual Studio 2019.
.NET Framework 4.7.2
Only Microsoft.CrmSdk.XrmTooling.CoreAssembly nuget package was installed the other packages were installed as dependencies.
Program - console application entry point with main method.
Services\RelationshipMetadataService - main class that gets all relationships for each entity in the CRM instance
Dtos\RelationshipDto - Data transfer object containing relationship information to be saved to a CSV file (fields are; ReferencedEntity, ReferencingEntity, RelationshipName, RelationshipType and CascadeShares).
ExtensionMethods\EnumerabeExtension - class contains an extension method to write the data in an IEnumerables to a CSV file.
ExtensionMethods\ManyToManyRelationshipMetadataExtension - class that contains an extension method to convert ManyToManyRelationshipMetadata generic list to a Relationship DTO generic list
ExtensionMethods\OneToManyRelationshipMetadataExtension - class that contains an extension method to convert OneToManyRelationshipMetadata generic list to a Relationship DTO generic list.