Bagikan melalui


Entity.GetAttributeValue<T> Method (String)

 

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

Gets the value of the attribute.

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

Syntax

public virtual T GetAttributeValue<T>(
    string attributeLogicalName
)
Public Overridable Function GetAttributeValue(Of T) (
    attributeLogicalName As String
) As T

Parameters

Return Value

Type: T

Type: Type
The value of the attribute.

Type Parameters

  • T
    Type: Type. The type of the attribute.

Remarks

You should only use this method for attributes you know were requested in the query that retrieved the entity. You can use Entity.Contains to check whether the entity instance includes the attribute.

When an entity instance does not include the attribute specified using the attributeLogicalName parameter this method will return null or the default value for the type rather than throw an exception. You should not assume that the entity includes the attribute. It may not be included if the code that retrieved the attribute didn’t request it.

The following table describes the default types for Dynamics Customer Engagement types which have default values:

CRM Type

.NET Type

Default Value

Two Options

Boolean

false

Whole Number

Int

0

Floating Point Number

Double

0.0

Currency

Decimal

0

Date and Time

DateTime

DateTime.MinValue(01/01/0001)

As mentioned above, getAttributeValue will return the default value rather than null for these attributes when the attribute is not requested in the query.

Examples

GetAttributeValue<EntityReference>("regardingobjectid")

See Also

Entity Class
Microsoft.Xrm.Sdk Namespace
Blog Post: Entity.GetAttributeValue<T> Explained

Return to top

Microsoft Dynamics 365

© 2017 Microsoft. All rights reserved. Copyright