Exemplo n.º 1
0
        private ExpressionToSql <T> SelectParser(Expression expression, Expression expressionBody, params Type[] ary)
        {
            this._sqlBuilder.Clear();
            this._sqlBuilder.IsSingleTable = false;

            foreach (var item in ary)
            {
                string tableName = item.Name;
                this._sqlBuilder.SetTableAlias(tableName);
            }

            string sql = "select {0}\nfrom " + typeof(T).Name + " " + this._sqlBuilder.GetTableAlias(typeof(T).Name);

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

            return(this);
        }
        private ExpressionToSql <T> SelectParser(Expression expression, Expression expressionBody, params Type[] ary)
        {
            this.Clear();
            this._sqlBuilder.IsSingleTable = false;

            if (expressionBody != null && expressionBody.Type == typeof(T))
            {
                throw new ArgumentException("cannot be parse expression", "expression");
            }

            foreach (var item in ary)
            {
                string tableName = item.Name;
                this._sqlBuilder.SetTableAlias(tableName);
            }

            string sql = "select {0}\nfrom " + this._mainTableName + " " + this._sqlBuilder.GetTableAlias(this._mainTableName);

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

            return(this);
        }
Exemplo n.º 3
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)
        {
            PropertyInfoCache.InitCacheInfo <T2>();
            PropertyInfoCache.InitCacheInfo <T3>();
            PropertyInfoCache.InitCacheInfo <T4>();
            PropertyInfoCache.InitCacheInfo <T5>();
            PropertyInfoCache.InitCacheInfo <T6>();
            PropertyInfoCache.InitCacheInfo <T7>();
            PropertyInfoCache.InitCacheInfo <T8>();
            PropertyInfoCache.InitCacheInfo <T9>();
            PropertyInfoCache.InitCacheInfo <T10>();

            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);
        }
 protected override SqlPack Select(NewExpression expression, SqlPack sqlPack)
 {
     foreach (Expression item in expression.Arguments)
     {
         Expression2SqlProvider.Select(item, sqlPack);
     }
     return(sqlPack);
 }
Exemplo n.º 5
0
        protected override SqlBuilder Select(NewExpression expression, SqlBuilder sqlBuilder)
        {
            foreach (Expression item in expression.Arguments)
            {
                Expression2SqlProvider.Select(item, sqlBuilder);
            }

            foreach (MemberInfo item in expression.Members)
            {
                sqlBuilder.SelectFieldsAlias.Add(item.Name);
            }

            return(sqlBuilder);
        }
Exemplo n.º 6
0
        public Expression2SqlCore <T> Select <T2, T3>(Expression <Func <T, T2, T3, object> > expression = null)
        {
            string sql = SelectParser(typeof(T), typeof(T2), typeof(T3));

            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);
        }
Exemplo n.º 7
0
        public Expression2SqlCore <T> Select(Expression <Func <T, object> > expression = null)
        {
            string sql = SelectParser(typeof(T));

            if (expression == null)
            {
                //this._sqlPack.Sql.AppendFormat(sql, "*");
                var fields = PropertyInfoCache.FieldNameAsPropertyName(typeof(T).FullName);
                this._sqlPack.Sql.AppendFormat(sql, fields);
            }
            else
            {
                Expression2SqlProvider.Select(expression.Body, this._sqlPack);
                this._sqlPack.Sql.AppendFormat(sql, this._sqlPack.SelectFieldsStr);
            }

            return(this);
        }
 protected override SqlBuilder Select(ParameterExpression expression, SqlBuilder sqlBuilder)
 {
     Expression2SqlProvider.Select(expression, sqlBuilder);
     return(sqlBuilder);
 }
Exemplo n.º 9
0
 protected override SqlBuilder Select(UnaryExpression expression, SqlBuilder sqlBuilder)
 {
     Expression2SqlProvider.Select(expression.Operand, sqlBuilder);
     return(sqlBuilder);
 }
Exemplo n.º 10
0
 protected override SqlPack Select(UnaryExpression expression, SqlPack sqlPack)
 {
     Expression2SqlProvider.Select(expression.Operand, sqlPack);
     return(sqlPack);
 }