crm 2016 按类型代码获取实体逻辑名称?

crm 2016 get entity logical name by type code?

我有实体的 Guid 和类型代码,如何通过类型代码检索没有逻辑名称的实体。

public void GetEntityReferenceByDynamicUrl(string dynamicUrl)
    {
        Uri entityUri = new Uri(dynamicUrl);
        var parameter = HttpUtility.ParseQueryString(entityUri.Query);

        if (parameter.AllKeys.Contains("id") && parameter.AllKeys.Contains("etc"))
        {
            var guid = new Guid(parameter.Get("id"));
           var  etc = parameter.Get("etc");

        }
    }

看起来您正在使用 C#,因此您可以通过元数据调用来完成此操作

// get your ETC as an Integer
var ETC = (int)parameter.Get("etc");
var entityLogicalName = "";

// Query setup
// Columns: "LogicalName"
// Criteria: "ObjectTypeCode eq ETC"
var metaQuery = new EntityQueryExpression
{
    Properties = new MetadataPropertiesExpression
    {
        AllProperties = false,
        PropertyNames = { "LogicalName" }
    },
    Criteria = new MetadataFilterExpression
    {
        FilterOperator = LogicalOperator.And,
        Conditions = { new MetadataConditionExpression("ObjectTypeCode", MetadataConditionOperator.Equals, ETC) }
    }
};

var response = (RetrieveMetadataChangesResponse)XrmService.Execute(new RetrieveMetadataChangesRequest{ Query = metaQuery });
if (response.EntityMetadata.Count == 1)
{
    entityLogicalName = response.EntityMetadata.First().LogicalName;
}
else
{
    // 0 or multiple results. Handle appropriately
}

希望对您有所帮助