private List <EntityMetadata> GetEntitiesWithAttributesAndRelationships() { MetadataPropertiesExpression relationshipProperties = new MetadataPropertiesExpression ( nameof(RelationshipMetadataBase.SchemaName) , nameof(OneToManyRelationshipMetadata.ReferencedEntity) , nameof(OneToManyRelationshipMetadata.ReferencingEntity) , nameof(OneToManyRelationshipMetadata.ReferencedAttribute) , nameof(OneToManyRelationshipMetadata.ReferencingAttribute) , nameof(ManyToManyRelationshipMetadata.Entity1LogicalName) , nameof(ManyToManyRelationshipMetadata.Entity2LogicalName) , nameof(ManyToManyRelationshipMetadata.Entity1IntersectAttribute) , nameof(ManyToManyRelationshipMetadata.Entity2IntersectAttribute) ) { AllProperties = false }; EntityQueryExpression entityQueryExpression = new EntityQueryExpression() { Properties = new MetadataPropertiesExpression() { AllProperties = true }, AttributeQuery = new AttributeQueryExpression() { Properties = new MetadataPropertiesExpression ( nameof(AttributeMetadata.LogicalName) , nameof(AttributeMetadata.AttributeOf) , nameof(AttributeMetadata.EntityLogicalName) , nameof(AttributeMetadata.DisplayName) , nameof(AttributeMetadata.Description) ) }, RelationshipQuery = new RelationshipQueryExpression() { Properties = relationshipProperties }, }; var isEntityKeyExists = _service.IsRequestExists(SdkMessageRequest.Instances.RetrieveEntityKeyRequest); if (isEntityKeyExists) { entityQueryExpression.KeyQuery = new EntityKeyQueryExpression() { Properties = new MetadataPropertiesExpression ( nameof(EntityKeyMetadata.LogicalName) , nameof(EntityKeyMetadata.EntityLogicalName) , nameof(EntityKeyMetadata.KeyAttributes) ) }; } RetrieveMetadataChangesRequest request = new RetrieveMetadataChangesRequest() { Query = entityQueryExpression, }; RetrieveMetadataChangesResponse response = (RetrieveMetadataChangesResponse)_service.Execute(request); var result = response.EntityMetadata.OrderBy(ent => ent.LogicalName).ToList(); return(result); }