top of page

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.


Cascade Share Configuration in Dynamics CRM
Cascade Share Configuration in Dynamics CRM

Console App CSV Output
Console App CSV Output


The Visual Studio Solution:

Print Relationship .NET Console Project Properties
Print Relationship .NET Console Project Properties

VS Project Properites

  • Uses Visual Studio 2019.

  • .NET Framework 4.7.2

  • Console Application

Nuget Packages

Only Microsoft.CrmSdk.XrmTooling.CoreAssembly nuget package was installed the other packages were installed as dependencies.


Print Relationship Console Project Installed Nuget Packages
Print Relationship Console Project Installed Nuget Packages

Classes

  • 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.

Program.cs

RelationshipMetadataService.cs

RelationshipDto.cs

EnumerabeExtension.cs

ManyToManyRelationshipMetadataExtension.cs

OneToManyRelationshipMetadataExtension.cs


485 views0 comments

Recent Posts

See All
bottom of page