コード例 #1
0
        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);
        }
コード例 #3
0
        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));
        }
コード例 #4
0
 /// <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);
 }
コード例 #5
0
 /// <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);
 }
コード例 #6
0
 /// <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);
 }