public static LogicalBinaryExpression NotIn(string fieldName, params object[] value)
 {
     if (value == null)
     {
         return(IsNotNull(fieldName));
     }
     return(NotIn(SqlExpression.Field(fieldName), new CollectionExpression(value.Select(x => Constant(x)))));
 }
Exemplo n.º 2
0
 public Queryable <T> Select(params Expression <Func <T, object> >[] fields)
 {
     foreach (var field in fields)
     {
         Fields.Add(SqlExpression.Field(field));
     }
     return(this);
 }
 public static LogicalBinaryExpression NotEqual(string fieldName, object value)
 {
     if (value == null)
     {
         return(IsNotNull(fieldName));
     }
     return(NotEqual(SqlExpression.Field(fieldName), SqlExpression.Constant(value)));
 }
Exemplo n.º 4
0
 public Queryable <T> GroupBy(Expression <Func <T, object> > field, LogicalBinaryExpression having)
 {
     Groups.Add(SqlExpression.Field(field));
     if (having != null)
     {
         _having = SqlExpression.AndAlso(_having, having);
     }
     return(this);
 }
Exemplo n.º 5
0
        public override string OutputSqlString(ISqlBuilder builder, ParameterCollection output)
        {
            if (_fields == null || _fields.Count == 0)
            {
                Fields.AddRang(accessor.MetaInfo.GetPropertyNames().Select(x => SqlExpression.Field(x)));
            }

            var topExpressions       = top > 0 ? builder.Constant(top) : string.Empty;
            var fieldExpressions     = Fields.OutputSqlString(builder, output);
            var tableExpression      = builder.BuildTableName(accessor.MetaInfo.Name);
            var conditionExpressions = _where != null?_where.OutputSqlString(builder, output) : string.Empty;

            var groupbyExpression = _groups != null && _groups.Count > 0 ? _groups.OutputSqlString(builder, output) : string.Empty;
            var havingExpression  = _groups != null && _groups.Count > 0 && _having != null?_having.OutputSqlString(builder, output) : string.Empty;

            var orderbyExpression = _orders != null && _orders.Count > 0 ? string.Join(",", _orders.Select(x => string.Concat(x.Key.OutputSqlString(builder, output), " ", x.Value ? "DESC" : "ASC"))) : string.Empty;

            if (startIndex < 0)
            {
                return(builder.QueryFormat(
                           topExpressions,       //top(10)
                           fieldExpressions,     //id,name,...
                           tableExpression,      //tableName
                           conditionExpressions, //where id>1 and...
                           groupbyExpression,    //group by name....
                           havingExpression,     //having count(name)>1 ...
                           orderbyExpression,    //order id
                           distinct ? Options | SqlOptions.Distinct : Options
                           ));
            }
            else
            {
                return(builder.QueryFormat(
                           fieldExpressions,     //id,name,...
                           tableExpression,      //tableName
                           conditionExpressions, //where id>1 and...
                           groupbyExpression,    //group by name....
                           havingExpression,     //having count(name)>1 ...
                           orderbyExpression,    //order id
                           startIndex,
                           rowCount,
                           distinct ? Options | SqlOptions.Distinct : Options
                           ));
            }
        }
Exemplo n.º 6
0
 public Queryable <T> Sum(Expression <Func <T, object> > field, string alias)
 {
     Fields.Add(SqlExpression.Alias(SqlExpression.Function("SUM", SqlExpression.Field(field)), alias));
     return(this);
 }
Exemplo n.º 7
0
 public Queryable <T> Select(Expression <Func <T, object> > field, string alias)
 {
     Fields.Add(SqlExpression.Field(field, alias));
     return(this);
 }
Exemplo n.º 8
0
 public Queryable <T> OrderBy(Expression <Func <T, object> > field, bool descending)
 {
     return(OrderBy(SqlExpression.Field(field), descending));
 }
Exemplo n.º 9
0
 public Queryable <T> GroupBy(params Expression <Func <T, object> >[] fields)
 {
     Groups.AddRang(fields.Select(x => SqlExpression.Field(x)));
     return(this);
 }
Exemplo n.º 10
0
 public Queryable <T> GroupBy(Expression <Func <T, object> > field)
 {
     Groups.Add(SqlExpression.Field(field));
     return(this);
 }
 public static LogicalBinaryExpression Like(string fieldName, object value, bool startWith, bool endWith)
 {
     return(Like(SqlExpression.Field(fieldName), SqlExpression.Constant(value), startWith, endWith));
 }
 public static LogicalBinaryExpression Between(string fieldName, object value1, object value2)
 {
     return(Between(SqlExpression.Field(fieldName), SqlExpression.Constant(value1), Constant(value2)));
 }
 public static LogicalBinaryExpression In(string fieldName, params object[] value)
 {
     return(In(SqlExpression.Field(fieldName), new CollectionExpression(value.Select(x => Constant(x)))));
 }
 public static LogicalBinaryExpression LessThanOrEqual(string fieldName, object value)
 {
     return(LessThanOrEqual(SqlExpression.Field(fieldName), SqlExpression.Constant(value)));
 }
 public static LogicalBinaryExpression GreaterThan(string fieldName, object value)
 {
     return(GreaterThan(SqlExpression.Field(fieldName), SqlExpression.Constant(value)));
 }
 public static LogicalBinaryExpression IsNotNull(string fieldName)
 {
     return(IsNotNull(SqlExpression.Field(fieldName)));
 }