Skip to content

Entity Extensions

Artem Grunin edited this page May 21, 2019 · 2 revisions

Entity Extensions

Set of extension methods for Microsoft.Xrm.Sdk.Entity base class.

GetFormatedValue

Simplifies getting values from Entity.FormattedValues collection.

public String GetFormatedValue(String attributeLogicalName);

GetAliasedValue

Simplifies getting values from linked entities attributes wraped in AliasedValue class. This kind of attributes can be queried by FetchExpression or QueryExpression using Linked Entities.

public T GetAliasedValue<T>(String attributeLogicalName, String alias);

GetAliasedEntity

Simplifies getting multiple linked entitiy attrubutes by allocating them to separate Entity.

public Entity GetAliasedEntity(String entityLogicalName, String alias = null);

GetAliasedEntity<T>

Generic version of GetAliasedEntity.

public T GetAliasedEntity<T>(String entityLogicalName, String alias = null) where T : Entity;

MergeAttributes

Add attributes form source Entity if they don't exist in target Entity. Very convenient way to compose attribute values from plugin Target and PreImage to operate single Entity instance.

public void MergeAttributes(Entity source);

SetAttributeValue

Safely sets attribute value.

public bool SetAttributeValue(String name, Object value);

ToEntityReference

Introduced in version 1.0.37

As it turns out, OOB ToEntityReference method is not copying KeyAttributes collection. New parameter has to be added to be valid override of ToEntityReference.

public EntityReference ToEntityReference(bool withKeys);