예제 #1
0
 public Expression2SqlCore <T> Sum(Expression <Func <T, object> > expression)
 {
     this._sqlPack.Clear();
     this._sqlPack.IsSingleTable = true;
     Expression2SqlProvider.Sum(expression.Body, this._sqlPack);
     return(this);
 }
예제 #2
0
 public Expression2SqlCore <T> Update(Expression <Func <object> > expression = null)
 {
     this._sqlPack.Clear();
     this._sqlPack.IsSingleTable = true;
     this._sqlPack += "update " + typeof(T).Name + " set ";
     Expression2SqlProvider.Update(expression.Body, this._sqlPack);
     return(this);
 }
예제 #3
0
 protected override SqlPack OrderBy(NewExpression expression, SqlPack sqlPack)
 {
     foreach (Expression item in expression.Arguments)
     {
         Expression2SqlProvider.OrderBy(item, sqlPack);
     }
     return(sqlPack);
 }
예제 #4
0
        private Expression2SqlCore <T> JoinParser2 <T2, T3>(Expression <Func <T2, T3, bool> > expression, string leftOrRightJoin = "")
        {
            string joinTableName = typeof(T3).Name;

            this._sqlPack.SetTableAlias(joinTableName);
            this._sqlPack.Sql.AppendFormat("\n{0}join {1} on", leftOrRightJoin, joinTableName + " " + this._sqlPack.GetTableAlias(joinTableName));
            Expression2SqlProvider.Join(expression.Body, this._sqlPack);
            return(this);
        }
예제 #5
0
 private static void LikeLeft(MethodCallExpression expression, SqlPack sqlPack)
 {
     if (expression.Object != null)
     {
         Expression2SqlProvider.Where(expression.Object, sqlPack);
     }
     Expression2SqlProvider.Where(expression.Arguments[0], sqlPack);
     sqlPack += " like '%' +";
     Expression2SqlProvider.Where(expression.Arguments[1], sqlPack);
 }
예제 #6
0
        public Expression2SqlCore <T> Count(Expression <Func <T, object> > expression = null)
        {
            this._sqlPack.Clear();
            this._sqlPack.IsSingleTable = true;
            if (expression == null)
            {
                this._sqlPack.Sql.AppendFormat("select count(*) from {0}", typeof(T).Name);
            }
            else
            {
                Expression2SqlProvider.Count(expression.Body, this._sqlPack);
            }

            return(this);
        }
예제 #7
0
        public Expression2SqlCore <T> Select <T2>(Expression <Func <T, T2, object> > expression = null)
        {
            string sql = SelectParser(typeof(T), typeof(T2));

            if (expression == null)
            {
                this._sqlPack.Sql.AppendFormat(sql, "*");
            }
            else
            {
                Expression2SqlProvider.Select(expression.Body, this._sqlPack);
                this._sqlPack.Sql.AppendFormat(sql, this._sqlPack.SelectFieldsStr);
            }

            return(this);
        }
예제 #8
0
        public Expression2SqlCore <T> Select <T2, T3, T4, T5, T6, T7, T8, T9, T10>(Expression <Func <T, T2, T3, T4, T5, T6, T7, T8, T9, T10, object> > expression = null)
        {
            string sql = SelectParser(typeof(T), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9), typeof(T10));

            if (expression == null)
            {
                this._sqlPack.Sql.AppendFormat(sql, "*");
            }
            else
            {
                Expression2SqlProvider.Select(expression.Body, this._sqlPack);
                this._sqlPack.Sql.AppendFormat(sql, this._sqlPack.SelectFieldsStr);
            }

            return(this);
        }
예제 #9
0
        protected override SqlPack In(NewArrayExpression expression, SqlPack sqlPack)
        {
            sqlPack += "(";
            //拼接具体值
            foreach (Expression expressionItem in expression.Expressions)
            {
                Expression2SqlProvider.In(expressionItem, sqlPack);
            }

            if (sqlPack.Sql[sqlPack.Sql.Length - 1] == ',')
            {
                sqlPack.Sql.Remove(sqlPack.Sql.Length - 1, 1);
            }

            sqlPack += ")";

            return(sqlPack);
        }
예제 #10
0
        protected override SqlPack Where(BinaryExpression expression, SqlPack sqlPack)
        {
            Expression2SqlProvider.Where(expression.Left, sqlPack);
            int signIndex = sqlPack.Length;

            Expression2SqlProvider.Where(expression.Right, sqlPack);
            int sqlLength = sqlPack.Length;

            if (sqlLength - signIndex == 5 && sqlPack.ToString().EndsWith("null"))
            {
                OperatorParser(expression.NodeType, signIndex, sqlPack, true);
            }
            else
            {
                OperatorParser(expression.NodeType, signIndex, sqlPack);
            }

            return(sqlPack);
        }
예제 #11
0
        /// <summary>
        /// Select 解析
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        public Expression2SqlCore <T> Select(Expression <Func <T, object> > expression = null)
        {
            ///获得sql
            string sql = SelectParser(typeof(T));

            ///判断查询所有字段
            if (expression == null)
            {
                this._sqlPack.Sql.AppendFormat(sql, "*");
            }
            else
            {
                ///解析要查询的字段
                Expression2SqlProvider.Select(expression.Body, this._sqlPack);
                this._sqlPack.Sql.AppendFormat(sql, this._sqlPack.SelectFieldsStr);
            }

            return(this);
        }
예제 #12
0
 protected override SqlPack Select(UnaryExpression expression, SqlPack sqlPack)
 {
     ////获取一元运算的操作数。
     Expression2SqlProvider.Select(expression.Operand, sqlPack);
     return(sqlPack);
 }
예제 #13
0
 protected override SqlPack Sum(UnaryExpression expression, SqlPack sqlPack)
 {
     Expression2SqlProvider.Sum(expression.Operand, sqlPack);
     return(sqlPack);
 }
예제 #14
0
 private static void In(MethodCallExpression expression, SqlPack sqlPack)
 {
     Expression2SqlProvider.Where(expression.Arguments[0], sqlPack);
     sqlPack += " in";
     Expression2SqlProvider.In(expression.Arguments[1], sqlPack);
 }
예제 #15
0
 public Expression2SqlCore <T> OrderBy(Expression <Func <T, object> > expression)
 {
     this._sqlPack += "\norder by ";
     Expression2SqlProvider.OrderBy(expression.Body, this._sqlPack);
     return(this);
 }
예제 #16
0
 public Expression2SqlCore <T> GroupBy(Expression <Func <T, object> > expression)
 {
     this._sqlPack += "\ngroup by ";
     Expression2SqlProvider.GroupBy(expression.Body, this._sqlPack);
     return(this);
 }
예제 #17
0
 public Expression2SqlCore <T> Where(Expression <Func <T, bool> > expression)
 {
     this._sqlPack += "\nwhere";
     Expression2SqlProvider.Where(expression.Body, this._sqlPack);
     return(this);
 }