Skip to content

Entity Extensions

Artem Grunin edited this page Dec 30, 2024 · 4 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);

GetFormatedValue with alias

Introduced in version 1.0.37 Simplifies getting values from Entity.FormattedValues collection.

public String GetFormatedValue(string attributeLogicalName, string alias);

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);

RemoveUnchanged

Introduced in version 2.2.0

Remove attributes form target Entity if they have the same value in source Entity

Note that EntityCollection attributes are compared only by Entity Id's

public void RemoveUnchanged(this Entity target, Entity source)