Ejemplo n.º 1
0
        /// <inheritdoc />
        public IQuery <T> WhereAny(IEnumerable <Expression <Func <T, bool> > > predicates)
        {
            if (predicates == null)
            {
                return(this);
            }

            StringBuilder sb         = null;
            List <object> parameters = null;
            Sql           sql        = null;

            foreach (var predicate in predicates)
            {
                // see notes in Where()
                var expressionHelper = new ModelToSqlExpressionHelper <T>();
                var whereExpression  = expressionHelper.Visit(predicate);

                if (sb == null)
                {
                    sb         = new StringBuilder("(");
                    parameters = new List <object>();
                    sql        = new Sql();
                }
                else
                {
                    sb.Append(" OR ");
                    sql.Append(" OR ");
                }

                sb.Append(whereExpression);
                parameters.AddRange(expressionHelper.GetSqlParameters());
                sql.Append(whereExpression, expressionHelper.GetSqlParameters());
            }

            if (sb == null)
            {
                return(this);
            }

            sb.Append(")");
            //_wheres.Add(Tuple.Create(sb.ToString(), parameters.ToArray()));
            _wheres.Add(Tuple.Create("(" + sql.SQL + ")", sql.Arguments));

            return(this);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds a where clause to the query
        /// </summary>
        /// <param name="predicate"></param>
        /// <returns>This instance so calls to this method are chainable</returns>
        public virtual IQuery <T> Where(Expression <Func <T, bool> > predicate)
        {
            if (predicate != null)
            {
                var    expressionHelper = new ModelToSqlExpressionHelper <T>();
                string whereExpression  = expressionHelper.Visit(predicate);

                _wheres.Add(new Tuple <string, object[]>(whereExpression, expressionHelper.GetSqlParameters()));
            }
            return(this);
        }