Ejemplo n.º 1
0
		/// <summary>
		/// Builds a Linq To SQL expression from the given query filtering expression.
		/// </summary>
		/// <param name="expression">An expression to interpret.</param>
		/// <param name="entityParameter">The expression entity parameter.</param>
		/// <returns>A Linq To SQL expression.</returns>
		/// <exception cref="System.ArgumentNullException">The <paramref name="expression"/> is null.</exception>
		/// <exception cref="System.ArgumentException">The <paramref name="expression"/> contains an unknown filtering expression.</exception>
		public virtual Expression Interpret(QueryFilterExpression expression, ParameterExpression entityParameter)
		{
			Error.ArgumentNullException_IfNull(expression, "expression");
			Error.ArgumentNullException_IfNull(entityParameter, "entityParameter");

			var result = InterpretCondition(ExpressionBuilder.Contains, expression as ContainsCondition, entityParameter)
				?? InterpretCondition(ExpressionBuilder.NotContains, expression as NotContainsCondition, entityParameter)
				?? InterpretCondition(ExpressionBuilder.Equals, expression as EqualsCondition, entityParameter)
				?? InterpretCondition(ExpressionBuilder.NotEquals, expression as NotEqualsCondition, entityParameter)
				?? InterpretCondition(ExpressionBuilder.GreaterThan, expression as GreaterThanCondition, entityParameter)
				?? InterpretCondition(ExpressionBuilder.GreaterThanOrEquals, expression as GreaterThanOrEqualsCondition, entityParameter)
				?? InterpretCondition(ExpressionBuilder.LessThan, expression as LessThanCondition, entityParameter)
				?? InterpretCondition(ExpressionBuilder.LessThanOrEquals, expression as LessThanOrEqualsCondition, entityParameter)
				?? InterpretCondition(ExpressionBuilder.IsNull, expression as IsNullCondition, entityParameter)
				?? InterpretCondition(ExpressionBuilder.IsNotNull, expression as IsNotNullCondition, entityParameter)
				?? InterpretOperator(ExpressionBuilder.And, expression as AndOperator, entityParameter)
				?? InterpretOperator(ExpressionBuilder.Or, expression as OrOperator, entityParameter)
				?? InterpretOperator(ExpressionBuilder.Not, expression as NotOperator, entityParameter);

			if (result != null)
			{
				return result;
			}

			DAError.ArgumentException_UnknownQueryFilterExpression(expression);

			return null;
		}
Ejemplo n.º 2
0
        /// <summary>
        /// Configures a related entity of the given entity.
        /// </summary>
        /// <typeparam name="TProperty">The type of the related entity property.</typeparam>
        /// <typeparam name="TKey">The type of the related entity key.</typeparam>
        /// <param name="relatedEntityProperty">The related entity property.</param>
        /// <param name="relatedEntityKey">The related entity key.</param>
        /// <returns>The configuration ovject of the given entity.</returns>
        /// <exception cref="System.ArgumentNullException">The <paramref name="relatedEntityProperty"/> is null.</exception>
        /// <exception cref="System.ArgumentException">The <paramref name="relatedEntityProperty"/> is not an one level property expression.</exception>
        public RelatedEntityItemConfiguration <TEntity, TProperty> WithEntity <TProperty, TKey>(
            Expression <Func <TItem, TProperty> > relatedEntityProperty,
            Expression <Func <TItem, TKey> > relatedEntityKey)
            where TProperty : class
        {
            Error.ArgumentNullException_IfNull(relatedEntityProperty, "relatedEntityProperty");
            DAError.ArgumentException_IfNotOneLevelPropertyExpression(relatedEntityProperty);
            if (relatedEntityKey != null)
            {
                DAError.ArgumentException_IfNotOneLevelPropertyExpression(relatedEntityKey);
            }

            var memberProperty = ReflectionHelper.GetPropertyName(relatedEntityProperty);
            var memberKey      = relatedEntityKey != null?ReflectionHelper.GetPropertyName(relatedEntityKey) : string.Empty;

            var newMember = new RelatedEntityInfo(
                string.Format(newMemberFormat2, currentRelatedEntityInfo.RelatedPropertyPath, memberProperty),
                string.Format(newMemberFormat2, currentRelatedEntityInfo.RelatedKeyPath, memberKey));

            if (!relatedEntityInfo.Contains(newMember))
            {
                relatedEntityInfo.Remove(currentRelatedEntityInfo);

                relatedEntityInfo.Add(newMember);
            }

            return(new RelatedEntityItemConfiguration <TEntity, TProperty>(
                       relatedEntityInfo, newMember, subEntityInfo, usedEntityInfo, usingEntityInfo));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Configures using entities for the entity.
        /// </summary>
        /// <typeparam name="TProperty">The type of the using entities property.</typeparam>
        /// <param name="usingEntitiesProperty">The using collection.</param>
        /// <returns>The configuration object to configure a using entities.</returns>
        /// <exception cref="System.ArgumentNullException">The <paramref name="usingEntitiesProperty"/> is null.</exception>
        /// <exception cref="System.ArgumentException">The <paramref name="usingEntitiesProperty"/> is not an one level property expression.</exception>
        public RelatedEntityItemConfiguration <TEntity, TProperty> IsUsedByEntities <TProperty>(
            Expression <Func <TEntity, ICollection <TProperty> > > usingEntitiesProperty)
            where TProperty : class
        {
            Error.ArgumentNullException_IfNull(usingEntitiesProperty, "usingEntitiesProperty");
            DAError.ArgumentException_IfNotOneLevelPropertyExpression(usingEntitiesProperty);

            var member = new RelatedEntityInfo(ReflectionHelper.GetPropertyName(usingEntitiesProperty), string.Empty);

            if (!usingEntityInfo.Contains(member))
            {
                usingEntityInfo.Add(member);
            }

            return(new RelatedEntityItemConfiguration <TEntity, TProperty>(
                       usingEntityInfo, member, subEntityInfo, usedEntityInfo, usingEntityInfo));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Configures a sub entity of the entity.
        /// </summary>
        /// <typeparam name="TProperty">The type of the sub entity property.</typeparam>
        /// <typeparam name="TKey">The type of the sub entity key.</typeparam>
        /// <param name="subEntityProperty">The sub entity property.</param>
        /// <param name="subEntityKey">The sub entity key.</param>
        /// <returns>The configuration object for related entities.</returns>
        /// <exception cref="System.ArgumentNullException">The <paramref name="subEntityProperty"/> is null.</exception>
        /// <exception cref="System.ArgumentException">The <paramref name="subEntityProperty"/> or
        /// <paramref name="subEntityKey"/> is not an one level property expression.</exception>
        public RelatedEntityItemConfiguration <TEntity, TProperty> HasSubEntity <TProperty, TKey>(
            Expression <Func <TEntity, TProperty> > subEntityProperty, Expression <Func <TEntity, TKey> > subEntityKey)
            where TProperty : class
        {
            Error.ArgumentNullException_IfNull(subEntityProperty, "subEntityProperty");
            DAError.ArgumentException_IfNotOneLevelPropertyExpression(subEntityProperty);
            if (subEntityKey != null)
            {
                DAError.ArgumentException_IfNotOneLevelPropertyExpression(subEntityKey);
            }

            var member = new RelatedEntityInfo(ReflectionHelper.GetPropertyName(subEntityProperty),
                                               subEntityKey != null ? ReflectionHelper.GetPropertyName(subEntityKey) : string.Empty);

            if (!subEntityInfo.Contains(member))
            {
                subEntityInfo.Add(member);
            }

            return(new RelatedEntityItemConfiguration <TEntity, TProperty>(
                       subEntityInfo, member, subEntityInfo, usedEntityInfo, usingEntityInfo));
        }