protected static string ApplyWhereSubOperations(StandardProviderParameters std, tgDynamicQuerySerializable query, tgComparison.tgComparisonData comparisonData) { string sql = string.Empty; if (comparisonData.HasExpression) { sql += GetMathmaticalExpressionColumn(std, query, comparisonData.Expression); if (comparisonData.SubOperators != null && comparisonData.SubOperators.Count > 0) { sql = BuildSubOperationsSql(std, sql, comparisonData.SubOperators); } return sql; } string delimitedColumnName = GetColumnName(comparisonData.Column); if (comparisonData.SubOperators != null) { sql = BuildSubOperationsSql(std, delimitedColumnName, comparisonData.SubOperators); } else { sql = delimitedColumnName; } return sql; }
/// <summary> /// Used to describe the "where" conditions of the join itself /// </summary> /// <param name="items"></param> /// <returns></returns> public tgDynamicQuerySerializable On(params object[] items) { if (this.data.WhereItems == null) { this.data.WhereItems = new List <tgComparison>(); } foreach (object item in items) { tgComparison wi = item as tgComparison; if (wi != null) { if (wi.data.WhereExpression != null) { foreach (tgComparison exp in wi.data.WhereExpression) { tgDynamicQuerySerializable q = exp.Value as tgDynamicQuerySerializable; if (q != null) { IDynamicQuerySerializableInternal iQ = q as IDynamicQuerySerializableInternal; iQ.HookupProviderMetadata(q); } } this.data.WhereItems.AddRange(wi.data.WhereExpression); } else { this.data.WhereItems.Add(wi); } tgDynamicQuerySerializable query = wi.Value as tgDynamicQuerySerializable; if (query != null) { IDynamicQuerySerializableInternal iQ = query as IDynamicQuerySerializableInternal; iQ.HookupProviderMetadata(query); } } else { throw new Exception("Unsupported Join Syntax"); } } return(this.parentQuery); }
/// <summary> /// /// </summary> /// <param name="c1"></param> /// <param name="c2"></param> /// <param name="op"></param> /// <returns></returns> private static tgComparison HandleOperator(tgComparison c1, tgComparison c2, tgConjunction op) { List <tgComparison> exp = null; if (c1.data.WhereExpression == null) { c1.data.WhereExpression = new List <tgComparison>(); exp = c1.data.WhereExpression; exp.Add(new tgComparison(tgParenthesis.Open)); exp.Add(c1); } else { exp = c1.data.WhereExpression; exp.Insert(0, new tgComparison(tgParenthesis.Open)); } tgConjunction conj = op; if (c2.not) { switch (op) { case tgConjunction.And: conj = tgConjunction.AndNot; break; case tgConjunction.Or: conj = tgConjunction.OrNot; break; } } exp.Add(new tgComparison(conj)); if (c2.data.WhereExpression == null) { exp.Add(c2); } else { exp.AddRange(c2.data.WhereExpression); } exp.Add(new tgComparison(tgParenthesis.Close)); return(c1); }
protected static string ApplyWhereSubOperations(StandardProviderParameters std, tgDynamicQuerySerializable query, tgComparison.tgComparisonData comparisonData) { string sql = string.Empty; string delimitedColumnName = GetColumnName(comparisonData.Column); if (comparisonData.SubOperators != null) { sql = BuildSubOperationsSql(std, delimitedColumnName, comparisonData.SubOperators); } else { sql = delimitedColumnName; } return sql; }
public tgCase When(tgComparison comparison) { this.WhenItem = new tgExpressionOrComparison(); this.WhenItem.Comparisons = new List <tgComparison>(); if (comparison != null) { if (comparison.data.WhereExpression != null) { foreach (tgComparison exp in comparison.data.WhereExpression) { tgDynamicQuerySerializable q = exp.Value as tgDynamicQuerySerializable; if (q != null) { IDynamicQuerySerializableInternal iQ = q as IDynamicQuerySerializableInternal; iQ.HookupProviderMetadata(q); } } this.WhenItem.Comparisons.AddRange(comparison.data.WhereExpression); } else { this.WhenItem.Comparisons.Add(comparison); } tgDynamicQuerySerializable query = comparison.Value as tgDynamicQuerySerializable; if (query != null) { IDynamicQuerySerializableInternal iQ = query as IDynamicQuerySerializableInternal; iQ.HookupProviderMetadata(query); } } return(this); }
private static tgComparison GreaterThanOrEqual(tgQueryItem queryItem, object literal, tgSystemType literalType, bool itemFirst) { tgComparison wi = new tgComparison(queryItem.query); wi.Operand = tgComparisonOperand.GreaterThanOrEqual; wi.data.Column = queryItem.Column; wi.data.Value = literal; wi.data.Expression = queryItem.Expression; wi.data.ItemFirst = itemFirst; wi.SubOperators = queryItem.SubOperators; return wi; }
/// <summary> /// Greater Than or Equal >= (to use in Where clauses). /// </summary> /// <example> /// The operators provide an alternative, natural syntax for DynamicQueries. /// <code> /// emps.Query.Where(emps.Query.BirthDate >= "2000-01-01"); /// </code> /// </example> /// <param name="item">Passed in via DynamicQuery</param> /// <param name="value">Passed in via DynamicQuery</param> /// <returns>The tgComparison returned to DynamicQuery</returns> public static tgComparison operator >=(tgQueryItem item, tgQueryItem value) { tgComparison wi = new tgComparison(item.query); wi.Operand = tgComparisonOperand.GreaterThanOrEqual; wi.data.Column = item.Column; wi.data.ComparisonColumn = value.Column; wi.SubOperators = item.SubOperators; return wi; }
/// <summary> /// Comparison ensuring that this column is NOT IN a list of values. /// </summary> /// <param name="value">The Query to provide the matching values for the NOT IN comparison</param> /// <returns></returns> public tgComparison NotIn(tgDynamicQuerySerializable subQuery) { tgComparison comparison = new tgComparison(this.query); comparison.Operand = tgComparisonOperand.NotIn; comparison.data.Column = this.Column; comparison.SubOperators = this.SubOperators; comparison.Value = subQuery; this.query.AddQueryToList(subQuery); return comparison; }
/// <summary> /// Comparison ensuring that this column is NOT IN a list of values. /// See <see cref="tgComparisonOperand"/> Enumeration. /// </summary> /// <example> /// <code> /// Where(LastName.NotIn("Doe", "Smith", "Johnson")) /// </code> /// </example> /// <param name="value">The list of values for comparison.</param> /// <returns>The tgComparison returned to DynamicQuery.</returns> public tgComparison NotIn(params object[] value) { List<object> values = new List<object>(); #region Convert object[] into a List<object> object[] oValues = (object[])value; foreach (object o in oValues) { string str = o as string; if (str != null) { // String supports IEnumerable and we don't want to break // up each individual character values.Add(o); } else { IEnumerable enumer = o as IEnumerable; if (enumer != null) { foreach (object oo in enumer) { values.Add(oo); } } else { values.Add(o); } } } #endregion tgComparison comparison = new tgComparison(this.query); comparison.Operand = tgComparisonOperand.NotIn; comparison.data.Column = this.Column; comparison.SubOperators = this.SubOperators; comparison.Values = values; return comparison; }
/// <summary> /// Comparison ensuring that this column is BETWEEN two values. /// See <see cref="tgComparisonOperand"/> Enumeration. /// </summary> /// <example> /// <code> /// Where(BirthDate.Between("2000-01-01", "2000-12-31")) /// </code> /// </example> /// <param name="start">The starting value for comparison.</param> /// <param name="end">The ending value for comparison.</param> /// <returns>The tgComparison returned to DynamicQuery.</returns> public tgComparison Between(object start, object end) { tgComparison comparison = new tgComparison(this.query); comparison.Operand = tgComparisonOperand.Between; comparison.SubOperators = this.SubOperators; comparison.data.Column = this.Column; tgQueryItem qi = start as tgQueryItem; if (Object.Equals(qi, null)) { comparison.BetweenBegin = start; } else { comparison.data.ComparisonColumn = qi.Column; } qi = end as tgQueryItem; if (Object.Equals(qi, null)) { comparison.BetweenEnd = end; } else { comparison.data.ComparisonColumn2 = qi.Column; } comparison.SubOperators = this.SubOperators; return comparison; }
/// <summary> /// Comparison ensuring that the value passed in is NOT LIKE this column. /// This overload takes a single escape character. /// See <see cref="tgComparisonOperand"/> Enumeration. /// </summary> /// <example> /// The optional escape character is used if the search phrase /// contains one of the LIKE wildcards. For example, /// the following will exclude columns with "30%" anywhere in them. /// <code> /// Where(Discount.NotLike("%30!//", '!')) /// </code> /// </example> /// <param name="value">The value for comparison.</param> /// <param name="escapeCharacter">The single escape character.</param> /// <returns>The tgComparison returned to DynamicQuery.</returns> public tgComparison NotLike(object value, char escapeCharacter) { tgComparison comparison = new tgComparison(this.query); comparison.data.Column = this.Column; comparison.data.LikeEscape = escapeCharacter; comparison.Operand = tgComparisonOperand.NotLike; comparison.SubOperators = this.SubOperators; tgQueryItem qi = value as tgQueryItem; if (Object.Equals(qi, null)) { comparison.data.Value = value; } else { comparison.data.ComparisonColumn = qi.Column; } return comparison; }
private tgComparison CreateComparisonParameter(tgComparisonOperand operand) { tgComparison comparison = new tgComparison(this.query); comparison.Operand = operand; if (this.HasExpression) { comparison.data.Expression = this.Expression; } comparison.data.Column = this.Column; comparison.SubOperators = this.SubOperators; return comparison; }
private tgComparison CreateComparisonParameter(tgComparisonOperand operand, object value) { tgComparison comparison = null; tgQueryItem qi = value as tgQueryItem; if (Object.Equals(qi, null)) { comparison = new tgComparison(this.query); comparison.Operand = operand; if (this.HasExpression) { comparison.data.Expression = this.Expression; } comparison.data.Column = this.Column; comparison.data.Value = value; comparison.SubOperators = this.SubOperators; } else { comparison = new tgComparison(this.query); comparison.Operand = operand; comparison.data.Column = this.Column; comparison.data.ComparisonColumn = qi.Column; comparison.SubOperators = qi.SubOperators; } return comparison; }
/// <summary> /// /// </summary> /// <param name="c1"></param> /// <param name="c2"></param> /// <param name="op"></param> /// <returns></returns> private static tgComparison HandleOperator(tgComparison c1, tgComparison c2, tgConjunction op) { List<tgComparison> exp = null; if (c1.data.WhereExpression == null) { c1.data.WhereExpression = new List<tgComparison>(); exp = c1.data.WhereExpression; exp.Add(new tgComparison(tgParenthesis.Open)); exp.Add(c1); } else { exp = c1.data.WhereExpression; exp.Insert(0, new tgComparison(tgParenthesis.Open)); } tgConjunction conj = op; if (c2.not) { switch (op) { case tgConjunction.And: conj = tgConjunction.AndNot; break; case tgConjunction.Or: conj = tgConjunction.OrNot; break; } } exp.Add(new tgComparison(conj)); if (c2.data.WhereExpression == null) { exp.Add(c2); } else { exp.AddRange(c2.data.WhereExpression); } exp.Add(new tgComparison(tgParenthesis.Close)); return c1; }
public tgCase When(tgComparison comparison) { this.WhenItem = new tgExpressionOrComparison(); this.WhenItem.Comparisons = new List<tgComparison>(); if (comparison != null) { if (comparison.data.WhereExpression != null) { foreach (tgComparison exp in comparison.data.WhereExpression) { tgDynamicQuerySerializable q = exp.Value as tgDynamicQuerySerializable; if (q != null) { IDynamicQuerySerializableInternal iQ = q as IDynamicQuerySerializableInternal; iQ.HookupProviderMetadata(q); } } this.WhenItem.Comparisons.AddRange(comparison.data.WhereExpression); } else { this.WhenItem.Comparisons.Add(comparison); } tgDynamicQuerySerializable query = comparison.Value as tgDynamicQuerySerializable; if (query != null) { IDynamicQuerySerializableInternal iQ = query as IDynamicQuerySerializableInternal; iQ.HookupProviderMetadata(query); } } return this; }