Пример #1
0
        public static EntityKeyMetadata RetrieveEntityKeyMetadata(string entityLogicalName, string logicalName, Boolean retrieveAsIfPublished, IOrganizationService organizationService)
        {
            EntityKeyMetadata entityKeyMetadata = null;

            if (!string.IsNullOrEmpty(entityLogicalName) && !string.IsNullOrEmpty(logicalName))
            {
                try
                {
                    RetrieveEntityKeyRequest retrieveEntityKeyRequest = new RetrieveEntityKeyRequest()
                    {
                        EntityLogicalName     = entityLogicalName,
                        LogicalName           = logicalName,
                        MetadataId            = Guid.Empty,
                        RetrieveAsIfPublished = retrieveAsIfPublished,
                    };
                    RetrieveEntityKeyResponse retrieveEntityKeyResponse = (RetrieveEntityKeyResponse)organizationService.Execute(retrieveEntityKeyRequest);

                    //Null validation
                    if (retrieveEntityKeyResponse != null)
                    {
                        entityKeyMetadata = retrieveEntityKeyResponse.EntityKeyMetadata;
                    }
                }
                catch { }
            }

            return(entityKeyMetadata);
        }
Пример #2
0
        public static EntityKeyMetadata GetEntityKeyMetadata(IOrganizationService service, string entityLogicalName, Guid objectId)
        {
            RetrieveEntityKeyRequest attributeRequest = new RetrieveEntityKeyRequest
            {
                MetadataId            = objectId,
                RetrieveAsIfPublished = true,
                EntityLogicalName     = entityLogicalName,
            };
            RetrieveEntityKeyResponse attributeResponse =
                (RetrieveEntityKeyResponse)service.Execute(attributeRequest);

            return(attributeResponse.EntityKeyMetadata);
        }