none
如何查询某个实体的Crm2011 全局选项集?2011中如何获取某实体的EntityTypeCode RRS feed

答案

  • #region 查询实体元数据
            /// <summary>
            /// 查询实体数据
            /// </summary>
            /// <param name="service"></param>
            private List<CRMEntity> GetEntityMetadata(IOrganizationService service, bool isContainsAttribute = false)
            {
                List<CRMEntity> list = new List<CRMEntity>();
                RetrieveAllEntitiesRequest request;
                if (isContainsAttribute)
                {
                    request = new RetrieveAllEntitiesRequest()
                    {
                        EntityFilters = EntityFilters.Attributes,
    
    
                        RetrieveAsIfPublished = true
                    };
                }
                else
                {
                    request = new RetrieveAllEntitiesRequest()
                    {
                        EntityFilters = EntityFilters.Entity,
    
    
                        RetrieveAsIfPublished = true
                    };
                }
    
                // Retrieve the MetaData.
                RetrieveAllEntitiesResponse response = (RetrieveAllEntitiesResponse)service.Execute(request);
    
                foreach (var item in response.EntityMetadata)
                {
    
                    if (item.IsCustomizable.Value == true && string.IsNullOrEmpty(item.LogicalName) == false)
                    {
                        CRMEntity entity = new CRMEntity();
                        entity.ObjectTypeCode = item.ObjectTypeCode.ToString();
                        entity.DisPlayname = getDisplayName(item.DisplayName);
                        entity.LogicalName = item.LogicalName;
                        //Response.Write("ObjectTypeCode:" + item.ObjectTypeCode.ToString() + "   entityname:" + item.LogicalName + " displayname:" + getDisplayName(item.DisplayName) + "</br>");
                        GetAttributes(item, ref  entity);
                        list.Add(entity);
                    }
                }
                var data = list.OrderBy(c => c.LogicalName).OrderByDescending(c => c.LogicalName);
                return data.ToList();
            }
            /// <summary>
            /// 填充实体属性
            /// </summary>
            /// <param name="entity"></param>
            /// <param name="myentity"></param>
            public void GetAttributes(EntityMetadata entity, ref CRMEntity myentity)
            {
                List<CRMAttribute> list = new List<CRMAttribute>();
                if (entity.Attributes != null)
                {
                    foreach (var item in entity.Attributes)
                    {
                        if (item.IsCustomizable.Value == true)
                        {
                            CRMAttribute attibute = new CRMAttribute();
                            attibute.AttributeType = item.AttributeType.Value.ToString();
                            attibute.DisPlayname = getDisplayName(item.DisplayName);
                            attibute.LogicalName = item.LogicalName.ToString();
                            list.Add(attibute);
                            // Response.Write("LogicalName:" + item.LogicalName.ToString() + " displayname:" + getDisplayName(item.DisplayName) + "type;" + item.AttributeType.Value + "</br>");
                        }
                    }
                    myentity.Attributes = list.ToArray();
                }
            }
            string getDisplayName(Microsoft.Xrm.Sdk.Label lable2)
            {
                if (lable2.UserLocalizedLabel == null)
                    return string.Empty;
                else
                    return lable2.UserLocalizedLabel.Label;
    
            }
            #endregion


    windows live Id :hellohongfu@hotmail.com

    • 已标记为答案 Jemas Yang 2012年10月23日 7:26
    2012年4月20日 17:06

全部回复

  • SDK上有这样的消息你试试

    RetrieveEntityRequest

    RetrieveAttributeRequest


    windows live Id :hellohongfu@hotmail.com

    2012年4月18日 3:46
  • SDK上有这样的消息

    活性炭椰壳活性炭:http://www.hyhxtc.com

    2012年4月19日 13:10
  • #region 查询实体元数据
            /// <summary>
            /// 查询实体数据
            /// </summary>
            /// <param name="service"></param>
            private List<CRMEntity> GetEntityMetadata(IOrganizationService service, bool isContainsAttribute = false)
            {
                List<CRMEntity> list = new List<CRMEntity>();
                RetrieveAllEntitiesRequest request;
                if (isContainsAttribute)
                {
                    request = new RetrieveAllEntitiesRequest()
                    {
                        EntityFilters = EntityFilters.Attributes,
    
    
                        RetrieveAsIfPublished = true
                    };
                }
                else
                {
                    request = new RetrieveAllEntitiesRequest()
                    {
                        EntityFilters = EntityFilters.Entity,
    
    
                        RetrieveAsIfPublished = true
                    };
                }
    
                // Retrieve the MetaData.
                RetrieveAllEntitiesResponse response = (RetrieveAllEntitiesResponse)service.Execute(request);
    
                foreach (var item in response.EntityMetadata)
                {
    
                    if (item.IsCustomizable.Value == true && string.IsNullOrEmpty(item.LogicalName) == false)
                    {
                        CRMEntity entity = new CRMEntity();
                        entity.ObjectTypeCode = item.ObjectTypeCode.ToString();
                        entity.DisPlayname = getDisplayName(item.DisplayName);
                        entity.LogicalName = item.LogicalName;
                        //Response.Write("ObjectTypeCode:" + item.ObjectTypeCode.ToString() + "   entityname:" + item.LogicalName + " displayname:" + getDisplayName(item.DisplayName) + "</br>");
                        GetAttributes(item, ref  entity);
                        list.Add(entity);
                    }
                }
                var data = list.OrderBy(c => c.LogicalName).OrderByDescending(c => c.LogicalName);
                return data.ToList();
            }
            /// <summary>
            /// 填充实体属性
            /// </summary>
            /// <param name="entity"></param>
            /// <param name="myentity"></param>
            public void GetAttributes(EntityMetadata entity, ref CRMEntity myentity)
            {
                List<CRMAttribute> list = new List<CRMAttribute>();
                if (entity.Attributes != null)
                {
                    foreach (var item in entity.Attributes)
                    {
                        if (item.IsCustomizable.Value == true)
                        {
                            CRMAttribute attibute = new CRMAttribute();
                            attibute.AttributeType = item.AttributeType.Value.ToString();
                            attibute.DisPlayname = getDisplayName(item.DisplayName);
                            attibute.LogicalName = item.LogicalName.ToString();
                            list.Add(attibute);
                            // Response.Write("LogicalName:" + item.LogicalName.ToString() + " displayname:" + getDisplayName(item.DisplayName) + "type;" + item.AttributeType.Value + "</br>");
                        }
                    }
                    myentity.Attributes = list.ToArray();
                }
            }
            string getDisplayName(Microsoft.Xrm.Sdk.Label lable2)
            {
                if (lable2.UserLocalizedLabel == null)
                    return string.Empty;
                else
                    return lable2.UserLocalizedLabel.Label;
    
            }
            #endregion


    windows live Id :hellohongfu@hotmail.com

    • 已标记为答案 Jemas Yang 2012年10月23日 7:26
    2012年4月20日 17:06
  • 说的不错啊

    2012年10月23日 7:11
  • SDK上有这样的消息 www.ysthxt8.com
    2012年10月23日 7:13