Ejemplo n.º 1
0
        public virtual string Count(Expression <Func <T, bool> > predicate)
        {
            var query = new StringBuilder();

            if (!string.IsNullOrWhiteSpace(_ordering))
            {
                throw new InvalidOperationException("'Count()' and 'ORDER BY' conditions can't be used together");
            }

            var entityName = QueryBuilderHelper.GetFluentEntityName <T>();
            var selector   = string.Format("SELECT count() FROM {0} ", entityName);

            query.AppendLine(selector);

            var condition = predicate.Parse();

            if (!string.IsNullOrWhiteSpace(_condition))
            {
                _condition = string.Format("{0} AND ({1}) ", _condition, condition);
            }
            else
            {
                _condition = string.Format("WHERE ({0}) ", condition);
            }

            query.AppendLine(_condition);

            if (!string.IsNullOrWhiteSpace(_limit))
            {
                query.AppendLine(_limit);
            }

            return(query.ToString());
        }
Ejemplo n.º 2
0
        public virtual string Count()
        {
            if (!string.IsNullOrWhiteSpace(_ordering))
            {
                throw new InvalidOperationException("'Count()' and 'ORDER BY' conditions can't be used together");
            }

            var query = new StringBuilder();

            var entityName = QueryBuilderHelper.GetFluentEntityName <T>();
            var selector   = string.Format("SELECT count() FROM {0} ", entityName);

            query.AppendLine(selector);

            if (!string.IsNullOrWhiteSpace(_condition))
            {
                query.AppendLine(_condition);
            }

            if (!string.IsNullOrWhiteSpace(_limit))
            {
                query.AppendLine(_limit);
            }

            return(query.ToString());
        }
Ejemplo n.º 3
0
        protected virtual string GetSelector <TOut>() where TOut : class, new()
        {
            var entityName    = QueryBuilderHelper.GetFluentEntityName <T>();
            var propertyNames = QueryBuilderHelper.GetFluentPropertyNames <TOut>();
            var selector      = string.Format("SELECT {0} FROM {1} ", string.Join(", ", propertyNames), entityName);

            return(selector);
        }
Ejemplo n.º 4
0
        protected virtual string GetSelector <TOut>(Expression <Func <T, TOut> > predicate)
        {
            var entityName   = QueryBuilderHelper.GetFluentEntityName <T>();
            var propertyName = predicate.ParseMemberExpression();

            if (string.IsNullOrWhiteSpace(propertyName))
            {
                throw new ArgumentException("Argument 'predicate' should be a member access expression.");
            }

            var selector = string.Format("SELECT {0} FROM {1} ", propertyName, entityName);

            return(selector);
        }