簡體   English   中英

獲取邏輯名稱的顯示名稱

[英]Get display name for logical name

我有一個實體的邏輯名稱列表,我需要為其檢索顯示名稱。

例如,我有

List<string> _list=new List<string>();
_list.Add("address_City")
_list.Add("first_name")

它們的顯示名稱是“ 地址城市”和“ 名字”

RetrieveEntityRequest req = new RetrieveEntityRequest();
req.RetrieveAsIfPublished = true;
req.LogicalName = "account";
req.EntityFilters = EntityFilters.Attributes;

RetrieveEntityResponse resp = (RetrieveEntityResponse)_orgService.Execute(req);

for (int iCnt = 0; iCnt < resp.EntityMetadata.Attributes.ToList().Count; iCnt++)
{
    if(resp.EntityMetadata.Attributes.ToList()[iCnt].DisplayName.LocalizedLabels.Count>0)
    {
        string displayName = resp.EntityMetadata.Attributes.ToList()[iCnt].DisplayName.LocalizedLabels[0].Label;
        string logicalName = resp.EntityMetadata.Attributes.ToList()[iCnt].LogicalName;

    }
}

這段代碼檢索所有記錄。是否可以創建一些自定義查詢,在此我可以僅傳遞此List<string>並在那里檢索顯示名稱?

Linq會很棒。 只需獲取您的邏輯名稱列表並返回顯示名稱列表即可,如下所示:

List<string> _list = new List<string>()
                    {
                        "address_City",
                        "first_name"
                    };

List<string> _displayList = new List<string>();

if (entityMetaData.Attributes.Any())
{
    _displayList.AddRange(from lName in _list 
                          select (entityMetaData.Attributes.FirstOrDefault(n => n.LogicalName.Equals(lName))) 
                          into attribute 
                          where attribute.DisplayName.UserLocalizedLabel != null 
                          select attribute.DisplayName.UserLocalizedLabel.Label);
}

當返回帶有logicalName和displayName的字典時,可以使用相同的邏輯。 您從實體請求中獲得的響應已經具有所有元數據,因此在篩選數據並獲得所需內容時,您不會浪費太多時間。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM