public Dictionary <string, object> ToSqlString(StringBuilder where, bool with = true) { if (this.filterElements.Count == 0) { return(new Dictionary <string, object>()); } var parameters = Parameters; if (with) { where.Append('('); } for (int i = 0; i < this.filterElements.Count; i++) { IFilterElement el = filterElements[i]; if (i > 0) { where.Append(' ').Append(el.ConnOperator).Append(' '); } //Dokonalejsie riesenie by bolo overit ci nema field Alias a do WHERE podmienky poslat Aliasovany stlpec //Aktualne sa to robi iba pre PFE filtre. Mozno to bude padat akekolvek ine filtre. //Dokonalejsie riesenie je pre SORT, tak sa to robi tak, ze sa prebehnu fieldy na zoradenie a ak maju Alias tak sa pouzije el.ToSqlString(where); } if (with) { where.Append(')'); } return(parameters); }
private bool DoesMatchSettings(string logicalName, string kind, IFilterElement[] filters) { bool result = filters.Length == 0; for (int index = 0; index < filters.Length && !result; index++) { IFilterElement filterElement = filters[index]; Trace.Debug($"Match {kind} filter: {filterElement.Expression} on logical name: {logicalName}"); try { RegexOptions options = filterElement.IgnoreCase ? RegexOptions.IgnoreCase : ~RegexOptions.IgnoreCase; Regex regex = new Regex(filterElement.Expression, options); bool isMatch = regex.IsMatch(kind == "entity" ? logicalName : logicalName.Replace("*.", "")); Trace.Debug("{0} {1}", filterElement.Expression, isMatch ? "matches" : "does not match"); result |= isMatch; } catch (ArgumentException ex) { Trace.LogExceptionWarning(ex); } } return(result); }
public static IQueryable <T> Filter <T>(this IQueryable <T> query, IFilterElement filterElement) { var paramExpression = Expression.Parameter(typeof(T), "param"); var expr = filterElement.CreateExpression(paramExpression); var lambda = Expression.Lambda <Func <T, bool> >(expr, (ParameterExpression)paramExpression); return(query.Where(lambda)); }
/// <summary> /// Initializes a new instance of the <see cref="Filter" /> class with specified condition. /// </summary> public Filter(IFilterElement condition) { //check null?? this.filterElements.Add(condition); }
/// <summary> /// Appends specific condition to current instance with OR /// </summary> /// <returns>Actual filter instance (this)</returns> public Filter Or(IFilterElement condition) { condition.ConnOperator = FilterOperator.Or.Value; this.filterElements.Add(condition); return(this); }
/// <summary> /// Appends specific condition to current instance /// </summary> /// <returns>Actual filter instance (this)</returns> public Filter Append(IFilterElement condition) { this.filterElements.Add(condition); return(this); }