Делите путем


LabelQueryExpression Class

 

Applies To: Dynamics CRM 2015

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)

Inheritance Hierarchy

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

Syntax

[DataContractAttribute(Name = "LabelQueryExpression", Namespace = "https://schemas.microsoft.com/xrm/2011/Metadata/Query")]
public sealed class LabelQueryExpression : MetadataQueryBase
[DataContractAttribute(Name = "LabelQueryExpression", Namespace = "https://schemas.microsoft.com/xrm/2011/Metadata/Query")]
public ref class LabelQueryExpression sealed : MetadataQueryBase
[<Sealed>]
[<DataContractAttribute(Name = "LabelQueryExpression", Namespace = "https://schemas.microsoft.com/xrm/2011/Metadata/Query")>]
type LabelQueryExpression = 
    class
        inherit MetadataQueryBase
    end
<DataContractAttribute(Name := "LabelQueryExpression", Namespace := "https://schemas.microsoft.com/xrm/2011/Metadata/Query")>
Public NotInheritable Class LabelQueryExpression
    Inherits MetadataQueryBase

Constructors

Name Description
System_CAPS_pubmethod LabelQueryExpression()

Initializes a new instance of theLabelQueryExpression class.

Properties

Name Description
System_CAPS_pubproperty ExtensionData

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

System_CAPS_pubproperty FilterLanguages

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

System_CAPS_pubproperty MissingLabelBehavior

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.

Methods

Name Description
System_CAPS_pubmethod Equals(Object)

(Inherited from Object.)

System_CAPS_pubmethod GetHashCode()

(Inherited from Object.)

System_CAPS_pubmethod GetType()

(Inherited from Object.)

System_CAPS_pubmethod ToString()

(Inherited from Object.)

Remarks

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 d7d0b052-abca-4f81-9b86-0b9dc5e62a66#BKMK_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);

Thread Safety

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

See Also

Microsoft.Xrm.Sdk.Metadata.Query Namespace
Retrieve and detect changes to metadata
Customize labels to support multiple languages
Sample: Query metadata and detect changes

Return to top

© 2016 Microsoft. All rights reserved. Copyright