Ejemplo n.º 1
0
 /// <summary>
 /// Applies filters to the given query builder.
 /// </summary>
 /// <param name="builder"></param>
 public void ApplyToQuery(IDbQueryBuilder builder)
 {
     if (this.Filters.Count > 0)
     {
         builder.AddFilter(this.Filters);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds a set of WHERE clause conditions defined by the given expression, grouped by logical OR.
        /// </summary>
        /// <param name="query"></param>
        /// <param name="expression"></param>
        /// <returns></returns>
        public static IDbQueryBuilder WhereAny(this IDbQueryBuilder query, Action <IDbQueryWhereClause> expression)
        {
            query = query.Fork();
            var group = new DbQueryWhereClause(query.Root, SqlLogic.Or);

            expression.Invoke(group);

            query.AddFilter(group.Filters);

            return(query);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds a set of WHERE clause conditions by looping over the given collection, and then joining them together with the given logic.
        /// </summary>
        /// <param name="query"></param>
        /// <param name="list"></param>
        /// <param name="expression"></param>
        /// <returns></returns>
        public static IDbQueryBuilder WhereAny <TItem>(this IDbQueryBuilder query, IList <TItem> list, Action <IDbQueryWhereClause, TItem, int> expression)
        {
            query = query.Fork();
            var group = new DbQueryWhereClause(query.Root, SqlLogic.Or);

            for (var i = 0; i < list.Count; i++)
            {
                var innerGroup = new DbQueryWhereClause(query.Root, SqlLogic.And);
                expression.Invoke(innerGroup, list[i], i);
                group.AddFilter(innerGroup.Filters);
            }

            query.AddFilter(group.Filters);

            return(query);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Adds a set of WHERE clause conditions by looping over the given collection, and then joining them together with the given logic.
        /// </summary>
        /// <param name="query"></param>
        /// <param name="collection"></param>
        /// <param name="expression"></param>
        /// <returns></returns>
        public static IDbQueryBuilder WhereAny <TItem>(this IDbQueryBuilder query, IEnumerable <TItem> collection, Action <IDbQueryWhereClause, TItem> expression)
        {
            query = query.Fork();
            var group = new DbQueryWhereClause(query.Root, SqlLogic.Or);

            foreach (var item in collection)
            {
                var innerGroup = new DbQueryWhereClause(query.Root, SqlLogic.And);
                expression.Invoke(innerGroup, item);
                group.AddFilter(innerGroup.Filters);
            }

            query.AddFilter(group.Filters);

            return(query);
        }