LabelQueryExpression Class

 

Updated: November 29, 2016

Applies To: Dynamics 365 (online), Dynamics 365 (on-premises), Dynamics CRM 2016, Dynamics CRM Online

Defines the languages for the labels to be retrieved for metadata items that have labels.

Namespace:   Microsoft.Xrm.Sdk.Metadata.Query
Assembly:  Microsoft.Xrm.Sdk (in Microsoft.Xrm.Sdk.dll)

System.Object
  Microsoft.Xrm.Sdk.Metadata.Query.MetadataQueryBase
    Microsoft.Xrm.Sdk.Metadata.Query.LabelQueryExpression

[DataContractAttribute(Name = "LabelQueryExpression", Namespace = "http://schemas.microsoft.com/xrm/2011/Metadata/Query")]
public sealed class LabelQueryExpression : MetadataQueryBase

NameDescription
System_CAPS_pubmethodLabelQueryExpression()

Initializes a new instance of theLabelQueryExpression class.

NameDescription
System_CAPS_pubpropertyExtensionData

Gets or sets the structure that contains extra data.(Inherited from MetadataQueryBase.)

System_CAPS_pubpropertyFilterLanguages

Gets the LCID values for localized labels to be retrieved for metadata items.

System_CAPS_pubpropertyMissingLabelBehavior

When this optional parameter is set to 1, the query will include labels for the base language if the label for the requested language is not there.

NameDescription
System_CAPS_pubmethodEquals(Object)

(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

(Inherited from Object.)

System_CAPS_pubmethodGetType()

(Inherited from Object.)

System_CAPS_pubmethodToString()

(Inherited from Object.)

The number of labels returned for each item depends on the number of language packs installed by the organization. If no additional language packs are installed, there will only be labels for the organization base language. For best performance when additional language packs are installed you can limit labels to those that correspond to the user’s language preference. These preferences can be determined using the values returned by the client-side context getUserLcid function or by querying the UserSettings.UILanguageId value.

The following example shows those portions of the Sample: Query metadata and detect changes which deal with setting the LabelQueryExpression.



private Guid _userId;
private int _languageCode;



_userId = ((WhoAmIResponse)_service.Execute(new WhoAmIRequest())).UserId;
_languageCode = RetrieveUserUILanguageCode(_userId);



protected int RetrieveUserUILanguageCode(Guid userId)
{
 QueryExpression userSettingsQuery = new QueryExpression("usersettings");
 userSettingsQuery.ColumnSet.AddColumns("uilanguageid", "systemuserid");
 userSettingsQuery.Criteria.AddCondition("systemuserid", ConditionOperator.Equal, userId);
 EntityCollection userSettings = _service.RetrieveMultiple(userSettingsQuery);
 if (userSettings.Entities.Count > 0)
 {
  return (int)userSettings.Entities[0]["uilanguageid"];
 }
 return 0;
}




//A label query expression to limit the labels returned to only those for the user's preferred language
LabelQueryExpression labelQuery = new LabelQueryExpression();
labelQuery.FilterLanguages.Add(_languageCode);

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top

Microsoft Dynamics 365

© 2016 Microsoft. All rights reserved. Copyright

Community Additions

ADD
Show: