Beispiel #1
0
        /// <summary>
        /// Get Entity Metadata
        /// </summary>
        /// <param name="entityLogicalName">Entity Logical Name</param>
        /// <param name="entityFilter">Entity Filter</param>
        /// <param name="organizationService">Organization Service</param>
        /// <remarks>
        /// Return Entity Metadata
        /// </remarks>
        protected static EntityMetadata RetrieveEntityMetadata(string entityLogicalName, Microsoft.Xrm.Sdk.Metadata.EntityFilters entityFilter, IOrganizationService organizationService)
        {
            EntityMetadata entityMetadata = null;

            if (organizationService != null)
            {
                try
                {
                    OrganizationRequest request = new OrganizationRequest();
                    request.RequestName              = "RetrieveEntity";
                    request["EntityFilters"]         = entityFilter;
                    request["LogicalName"]           = entityLogicalName;
                    request["MetadataId"]            = Guid.Empty;
                    request["RetrieveAsIfPublished"] = true;

                    OrganizationResponse response = organizationService.Execute(request);
                    if (response != null)
                    {
                        entityMetadata = (EntityMetadata)response["EntityMetadata"];
                    }
                }
                catch { entityMetadata = null; }
            }

            return(entityMetadata);
        }
Beispiel #2
0
        public CRMEntityMetadata CRMGetEntityMetadata(CRMEntityMetadata entitytype)
        {
            OrganizationServiceProxy _serviceProxy;

            Microsoft.Xrm.Sdk.Metadata.EntityFilters filter = entitytype.IncludeAttributes ? Microsoft.Xrm.Sdk.Metadata.EntityFilters.Attributes : Microsoft.Xrm.Sdk.Metadata.EntityFilters.Entity;

            using (_serviceProxy = GetCRMConnection())
            {
                try
                {
                    RetrieveEntityRequest retrieveEntityRequest = new RetrieveEntityRequest
                    {
                        EntityFilters = filter,
                        LogicalName   = entitytype.LogicalName.ToLower()
                    };

                    RetrieveEntityResponse retrieveEntityResponse = (RetrieveEntityResponse)_serviceProxy.Execute(retrieveEntityRequest);
                    EntityMetadata         entityMetadata         = retrieveEntityResponse.EntityMetadata;

                    entitytype.DisplayName = entityMetadata.DisplayName.UserLocalizedLabel != null?entityMetadata.DisplayName.UserLocalizedLabel.Label.ToString() : entityMetadata.LogicalName;

                    entitytype.ObjectTypeCode       = entityMetadata.ObjectTypeCode.Value;
                    entitytype.LogicalName          = entityMetadata.LogicalName;
                    entitytype.PrimaryIdAttribute   = entityMetadata.PrimaryIdAttribute;
                    entitytype.PrimaryNameAttribute = entityMetadata.PrimaryNameAttribute;
                    entitytype.IsCustomEntity       = entityMetadata.IsCustomEntity.Value;
                    entitytype.Attributes           = new List <CRMAttribute>();

                    List <CRMAttribute> Attributes = new List <CRMAttribute>();
                    if (entitytype.IncludeAttributes)
                    {
                        foreach (AttributeMetadata metadata in entityMetadata.Attributes)
                        {
                            CRMAttribute attrib = new CRMAttribute();
                            attrib.AttributeType    = metadata.AttributeType.HasValue ? metadata.AttributeType.Value.ToString() : "";
                            attrib.Description      = metadata.Description.UserLocalizedLabel != null ? metadata.Description.UserLocalizedLabel.Label : "";
                            attrib.DisplayName      = metadata.DisplayName.UserLocalizedLabel != null ? metadata.DisplayName.UserLocalizedLabel.Label : metadata.LogicalName;
                            attrib.IsPrimaryId      = metadata.IsPrimaryId.HasValue ? metadata.IsPrimaryId.Value : false;
                            attrib.IsPrimaryName    = metadata.IsPrimaryName.HasValue ? metadata.IsPrimaryName.Value : false;
                            attrib.IsValidForCreate = metadata.IsValidForCreate.HasValue ? metadata.IsValidForCreate.Value : false;
                            attrib.IsValidForRead   = metadata.IsValidForRead.HasValue ? metadata.IsValidForRead.Value : false;
                            attrib.IsValidForUpdate = metadata.IsValidForUpdate.HasValue ? metadata.IsValidForUpdate.Value : false;
                            attrib.LogicalName      = metadata.LogicalName;
                            attrib.RequiredLevel    = metadata.RequiredLevel.Value.ToString();
                            attrib.SchemaName       = metadata.SchemaName;
                            Attributes.Add(attrib);
                        }
                        entitytype.Attributes = Attributes;
                    }
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
            return(entitytype);
        }
Beispiel #3
0
        public static EntityMetadata RetrieveMetadata(string entityName, Microsoft.Xrm.Sdk.Metadata.EntityFilters filter = EntityFilters.All, CrmConnection connection = null)
        {
            RetrieveEntityRequest request = new RetrieveEntityRequest()
            {
                EntityFilters         = filter,
                LogicalName           = entityName,
                RetrieveAsIfPublished = false
            };

            RetrieveEntityResponse response = Execute <RetrieveEntityRequest, RetrieveEntityResponse>(request, connection);

            return(response.EntityMetadata);
        }
        public static EntityMetadata GetEntityMataData(IOrganizationService svc, string entityName, Microsoft.Xrm.Sdk.Metadata.EntityFilters oFilter, bool retrieveAsIfPublished = true) {
            var oRequest = new RetrieveEntityRequest() {
                EntityFilters = oFilter,
                LogicalName = entityName,
                RetrieveAsIfPublished = retrieveAsIfPublished
            };

            return ((RetrieveEntityResponse)svc.Execute(oRequest)).EntityMetadata;
        }