/// <summary> /// Adds the aliased entity to the current entity. /// </summary> /// <param name="entity">The entity.</param> /// <param name="entityToAdd">The entity to add.</param> public static void AddAliasedEntity(this Entity entity, Entity entityToAdd) { foreach (var attribute in entityToAdd.Attributes.Where(a => !(a.Value is AliasedValue))) { entity.AddAliasedValue(entityToAdd.LogicalName, attribute.Key, attribute.Value); } }
/// <summary> /// Adds the aliased entity to the current entity. /// </summary> /// <param name="entity">The entity.</param> /// <param name="entityToAdd">The entity to add.</param> public static void AddAliasedEntity(this Entity entity, Entity entityToAdd) { foreach (var attribute in entityToAdd.Attributes.Where(a => !(a.Value is AliasedValue))) { var formattedValue = entityToAdd.FormattedValues.TryGetValue(attribute.Key, out var formatted) ? formatted : null; entity.AddAliasedValue(entityToAdd.LogicalName, attribute.Key, attribute.Value, formattedValue); } }
/// <summary> /// Adds the value to the entity as an Aliased Value, or replaces an already existing value. Helpful when you need to add attributes /// that are for other entities locally, in such a way that it looks like it was added by a link on a query /// expression /// </summary> /// <param name="entity"></param> /// <param name="logicalName">The logical name from which the aliased value would have come from</param> /// <param name="attributeName">The logical name of the attribute of the aliased value</param> /// <param name="value">The Value to store in the aliased value</param> public static void AddOrReplaceAliasedValue(this Entity entity, string logicalName, string attributeName, object value) { // Check for value already existing foreach (var attribute in entity.Attributes.Where(a => a.Value is AliasedValue)) { var aliasedValue = ((AliasedValue)attribute.Value); if (aliasedValue.EntityLogicalName != logicalName || aliasedValue.AttributeLogicalName != attributeName) { continue; } entity[attribute.Key] = new AliasedValue(aliasedValue.EntityLogicalName, aliasedValue.AttributeLogicalName, value); return; } entity.AddAliasedValue(logicalName, attributeName, value); }
/// <summary> /// Adds the value to the entity as an Aliased Value. Helpful when you need to add attributes /// that are for other entities locally, in such a way that it looks like it was added by a link on a query /// expression /// </summary> /// <param name="entity"></param> /// <param name="logicalName">The logical name from which the aliased value would have come from</param> /// <param name="attributeName">The logical name of the attribute of the aliased value</param> /// <param name="value">The Value to store in the aliased value</param> public static void AddAliasedValue(this Entity entity, string logicalName, string attributeName, object value) { entity.AddAliasedValue(null, logicalName, attributeName, value); }