/// <summary> /// append criteria group with logical operator to this query object /// </summary> /// <param name="criteriaGroup">criteria group to add</param> /// <param name="op">AND|OR the criteria group</param> public void Add(CriteriaGroup criteriaGroup, CriteriaGroupOperator op = CriteriaGroupOperator.And) { _criteriaGroups.Add( new Tuple <CriteriaGroup, CriteriaGroupOperator>( criteriaGroup, op)); }
/// <summary> /// append criteria with logical operator to this query object /// </summary> /// <param name="criteria">criteria to add</param> /// <param name="op">AND|OR the criteria</param> public void Add(Criteria criteria, CriteriaGroupOperator op = CriteriaGroupOperator.And) { _criteriaGroups.Add( new Tuple <CriteriaGroup, CriteriaGroupOperator>( new CriteriaGroup { Criterias = new List <Criteria> { criteria } }, op)); }
private void Build(StringBuilder builder, CriteriaGroupOperator op, CriteriaGroup criteriaGroup) { var sb = new StringBuilder(); foreach (var criteria in criteriaGroup.Criterias) { Build(sb, criteriaGroup.Operator, criteria); } if (sb.Length == 0) { return; } if (builder.Length > 0) { builder.AppendFormat(" {0} ", op); } builder.AppendFormat("({0})", sb); }
private void Build(StringBuilder builder, CriteriaGroupOperator op, Criteria criteria) { var property = GetPropertyInfo(typeof(T), criteria.Field); if (property == null) { return; } int valueIndex = _values.Count; if (criteria.Operator != CriteriaOperator.IsContainedIn && criteria.Operator != CriteriaOperator.IsNotContainedIn) { if (builder.Length > 0) { builder.AppendFormat(" {0} ", op); } if (criteria.Operator != CriteriaOperator.IsNull && criteria.Operator != CriteriaOperator.IsNotNull) { criteria.Value = ConvertEx.ChangeType(criteria.Value, property.PropertyType); _values.Add(criteria.Value); } } switch (criteria.Operator) { case CriteriaOperator.IsContainedIn: { var q = from z in criteria.Value.ToString().Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries) select new Criteria { Field = criteria.Field, Operator = CriteriaOperator.IsEqualTo, Value = z.Trim() }; var group = new CriteriaGroup { Operator = CriteriaGroupOperator.Or, Criterias = q.ToList() }; Build(builder, op, group); } break; case CriteriaOperator.IsNotContainedIn: { var q = from z in criteria.Value.ToString().Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries) select new Criteria { Field = criteria.Field, Operator = CriteriaOperator.IsNotEqualTo, Value = z.Trim() }; var group = new CriteriaGroup { Operator = CriteriaGroupOperator.And, Criterias = q.ToList() }; Build(builder, op, group); } break; default: var format = GetFormat(criteria.Operator, property.PropertyType); if (!string.IsNullOrEmpty(format)) { builder.AppendFormat(format, criteria.Field, valueIndex); } break; } }
public void Add(CriteriaGroup criteriaGroup, CriteriaGroupOperator op = CriteriaGroupOperator.And) { Build(_predicate, op, criteriaGroup); }