Exemple #1
0
        /// <summary>
        /// Sets the values to update as part of the operation. This clears any existing values.
        /// </summary>
        /// <typeparam name="TValue">
        /// The type of value to set the attribute to.
        /// </typeparam>
        /// <param name="attribute">
        /// The attribute to set.
        /// </param>
        /// <param name="value">
        /// The value to set the attribute to.
        /// </param>
        /// <returns>
        /// The current <see cref="UpdateSet{T}"/> with the specified attribute update value set.
        /// </returns>
        public UpdateSet <T> Set <TValue>([NotNull] Expression <Func <T, TValue> > attribute, TValue value)
        {
            if (attribute == null)
            {
                throw new ArgumentNullException(nameof(attribute));
            }

            var attributeLocation = new AttributeLocation(attribute);

            this.attributesToSet.Add(new ValueState(attributeLocation, value));
            return(this);
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ValueFilter"/> class.
        /// </summary>
        /// <param name="attributeLocation">
        /// The attribute location.
        /// </param>
        /// <param name="filterType">
        /// The filter type.
        /// </param>
        /// <param name="values">
        /// The values.
        /// </param>
        public ValueFilter([NotNull] AttributeLocation attributeLocation, FilterType filterType, [NotNull] params object[] values)
        {
            if (attributeLocation == null)
            {
                throw new ArgumentNullException(nameof(attributeLocation));
            }

            if (values == null)
            {
                throw new ArgumentNullException(nameof(values));
            }

            this.AttributeLocation = attributeLocation;
            this.FilterType        = filterType;
            this.values.AddRange(values);
        }
Exemple #3
0
        /// <inheritdoc />
        public EntityAttributeDefinition Find(AttributeLocation attributeLocation)
        {
            if (attributeLocation == null)
            {
                throw new ArgumentNullException(nameof(attributeLocation));
            }

            // TODO: Dictionary this!! Also lazy the lookup
            var reference  = this.DefinitionProvider.GetEntityReference(attributeLocation.PropertyInfo);
            var location   = this.DefinitionProvider.GetEntityLocation(reference);
            var entityName = attributeLocation.EntityReference.EntityAlias ?? location.Alias ?? location.Name;

            return(this.returnableAttributes.Value.FirstOrDefault(
                       definition => (definition.Entity.Alias ?? definition.Entity.Name) == entityName &&
                       definition.PropertyName == attributeLocation.PropertyInfo.Name));
        }
Exemple #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ValueState"/> class.
 /// </summary>
 /// <param name="attributeLocation">
 /// The attribute location.
 /// </param>
 /// <param name="value">
 /// The value of the attribute.
 /// </param>
 public ValueState([NotNull] AttributeLocation attributeLocation, object value)
 {
     this.AttributeLocation = attributeLocation ?? throw new ArgumentNullException(nameof(attributeLocation));
     this.Value             = value;
 }
Exemple #5
0
        /// <summary>
        /// Matches the primary key of the specified <paramref name="entity"/>.
        /// </summary>
        /// <param name="entity">
        /// The entity to match the key for.
        /// </param>
        /// <param name="definitionProvider">
        /// The definition provider for the entity.
        /// </param>
        /// <param name="explicitKeyAttributes">
        /// The explicit key attributes for this match.
        /// </param>
        /// <returns>
        /// The current <see cref="ValueFilterSet{T}"/>.
        /// </returns>
        /// <remarks>
        /// This operation will clear any existing filters.
        /// </remarks>
        public ValueFilterSet <T> MatchKey(
            [NotNull] T entity,
            [NotNull] IEntityDefinitionProvider definitionProvider,
            [NotNull] params Expression <Func <T, object> >[] explicitKeyAttributes)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            if (definitionProvider == null)
            {
                throw new ArgumentNullException(nameof(definitionProvider));
            }

            if (explicitKeyAttributes == null)
            {
                throw new ArgumentNullException(nameof(explicitKeyAttributes));
            }

            this.valueFilters.Clear();
            var entityDefinition = definitionProvider.Resolve <T>();
            var keyAttributes    = explicitKeyAttributes.Any()
                                    ? explicitKeyAttributes.Select(entityDefinition.Find)
                                    : entityDefinition.PrimaryKeyAttributes;

            foreach (var keyAttribute in keyAttributes)
            {
                var entityReference = new EntityReference
                {
                    EntityAlias = keyAttribute.Entity.Alias,
                    EntityType  = keyAttribute.Entity.EntityType
                };
                var attributeLocation = new AttributeLocation(keyAttribute.PropertyInfo, entityReference);
                var valueFilter       = new ValueFilter(attributeLocation, FilterType.Equality, keyAttribute.GetValueDelegate.DynamicInvoke(entity));

                this.valueFilters.Add(valueFilter);
            }

            // Use all available values if no keys are defined.
            if (this.valueFilters.Any())
            {
                return(this);
            }

            Trace.TraceWarning($"{typeof(T).FullName} does not have any key attributes defined.");

            foreach (var attribute in entityDefinition.DirectAttributes)
            {
                var entityReference = new EntityReference
                {
                    EntityAlias = attribute.Entity.Alias,
                    EntityType  = attribute.Entity.EntityType
                };
                var attributeLocation = new AttributeLocation(attribute.PropertyInfo, entityReference);
                var valueFilter       = new ValueFilter(attributeLocation, FilterType.Equality, attribute.GetValueDelegate.DynamicInvoke(entity));
                this.valueFilters.Add(valueFilter);
            }

            return(this);
        }