internal static void Parse(out ConditionList conditions, out OrderingList orderings, params IParameterMarker[] queryDesignerParameters) { conditions = new ConditionList(); orderings = new OrderingList(); foreach (IParameterMarker parameter in queryDesignerParameters) { if (parameter != null) { if (parameter is ConditionList) { conditions.AddConditions(parameter as IEnumerable<BaseCondition>); } else if (parameter is OrderingList) { orderings.AddOrderings(parameter as OrderingList); } else { throw new NotSupportedException("parameter"); } } conditions.RemoveDuplicates(); orderings.RemoveDuplicates(); } }
/// <summary> /// Creates <see cref="OrCondition"/> with the same <paramref name="fieldName"/> cref="fieldName"/> and differents <paramref name="values"/>. /// </summary> /// <param name="fieldName">name of a field which mapped with table.</param> /// <param name="values"></param> /// <param name="operator"></param> /// <param name="entityType">defines filtering Entity.</param> /// <returns><see cref="OrCondition"/> which contains <see cref="Condition"/> where the same /// <paramref name="fieldName"/> and differents <paramref name="values"/>. /// </returns> public static OrCondition Create(string fieldName, object[] values, ConditionOperator @operator, Type entityType) { Checker.CheckArgumentNull(fieldName, "fieldName"); if (values == null || values.Length == 0) { throw new ArgumentNullException("values"); } var conditionList = new ConditionList(); conditionList.AddConditions(fieldName, values, @operator, entityType); return new OrCondition(conditionList); }
private Expression MakeInnerJoin(Expression outerExpression, Expression innerExpression, string[] leftFieldsNames, string[] rightFieldsNames, ConditionList conditions) { Checker.CheckArgumentNull(outerExpression, "outerExpression"); Checker.CheckArgumentNull(innerExpression, "innerExpression"); Checker.CheckArgumentNull(leftFieldsNames, "leftFieldsNames"); Checker.CheckArgumentNull(outerExpression, "outerExpression"); int fieldsCount = leftFieldsNames.Length; if (fieldsCount != rightFieldsNames.Length) { throw new SpoltyException("Number of fields mismatch"); } Type outerType = ExpressionHelper.GetGenericType(outerExpression); ParameterExpression outerParam = ExpressionHelper.CreateOrGetParameterExpression(outerType, outerType.Name, Factory.Store); Type innerType = ExpressionHelper.GetGenericType(innerExpression); ParameterExpression innerParam = ExpressionHelper.CreateOrGetParameterExpression(innerType, innerType.Name, Factory.Store); var clw = new ConditionList(); for (int index = 1; index < fieldsCount; index++) { var fieldCondition = new FieldCondition(leftFieldsNames[index], ConditionOperator.EqualTo, rightFieldsNames[index], outerType, innerType); clw.Add(fieldCondition); } PropertyInfo outerPropertyInfo = outerType.GetProperty(leftFieldsNames[0]); if (outerPropertyInfo == null) { throw new SpoltyException("Property not found"); } PropertyInfo innerPropertyInfo = innerType.GetProperty(rightFieldsNames[0]); if (innerPropertyInfo == null) { throw new SpoltyException("Property not found"); } Expression outerPropertyExpression = Expression.Property(outerParam, outerPropertyInfo); Expression innerPropertyExpression = Expression.Property(innerParam, innerPropertyInfo); Type type = outerPropertyInfo.PropertyType; innerPropertyExpression = ExpressionHelper.ConvertOrCastInnerPropertyExpression(type, innerPropertyInfo, innerPropertyExpression); LambdaExpression outerKeySelector = Expression.Lambda(outerPropertyExpression, outerParam); LambdaExpression innerKeySelector = Expression.Lambda(innerPropertyExpression, innerParam); LambdaExpression resultSelector = Expression.Lambda(outerParam, outerParam, innerParam); if (conditions != null && conditions.Count > 0) { clw.AddConditions(conditions); } Expression resultJoinExpression = CallJoinMethod(outerExpression, innerExpression, outerKeySelector, innerKeySelector, resultSelector); resultJoinExpression = Factory.CreateConditionExpressionMaker().Make(clw, resultJoinExpression); return resultJoinExpression; }