Esempio n. 1
0
        protected override Expression VisitMethodCall(MethodCallExpression expression)
        {
            _genericType = ExpressionHelper.GetFirstGenericTypeArgumentOfType(expression.Method);

            _builder.Append("SELECT ");
            var secondArgument = expression.Arguments[1];

            var lambdaExpression     = (LambdaExpression)QueryHelper.StripQuotes(secondArgument);
            var bodyLambdaExpression = lambdaExpression.Body;

            Visit(bodyLambdaExpression);

            _builder.Append(" FROM ");

            var tableName = _mappingRuleTranslator.GetTableName(_genericType);

            _builder.Append(tableName);

            return(expression);
        }
Esempio n. 2
0
        /// <summary>
        /// When the class has finished to read the expression tree
        /// The function is called to generate the corresponding sql script.
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        private string GenerateSql(Expression expression)
        {
            if (!string.IsNullOrWhiteSpace(_translatedInsert))
            {
                return(_translatedInsert);
            }

            if (string.IsNullOrWhiteSpace(_translatedSelect) && !string.IsNullOrWhiteSpace(_translatedWhere))
            {
                var methodExpression = (MethodCallExpression)expression;
                var genericType      = ExpressionHelper.GetFirstGenericTypeArgumentOfType(methodExpression.Method);
                var tableName        = _mappingRuleTranslator.GetTableName(genericType);
                return("SELECT * FROM " + tableName + " " + _translatedWhere);
            }

            if (!string.IsNullOrWhiteSpace(_translatedSelect) && !string.IsNullOrWhiteSpace(_translatedWhere))
            {
                return(_translatedSelect + " " + _translatedWhere);
            }

            return(_translatedSelect);
        }
Esempio n. 3
0
        /// <summary>
        /// Visit the method call expression and fill in the T-SQL script
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        protected override Expression VisitMethodCall(MethodCallExpression expression)
        {
            var parameter = expression.Arguments[1];

            if (parameter == null)
            {
                // TODO : Throw the appropriate exception.
            }

            if (!expression.Method.IsGenericMethod)
            {
                // TODO : Throw the appropriate exception.
            }

            var firstParameter = expression.Method.GetGenericArguments().FirstOrDefault();

            _genericType = firstParameter;
            var tableName = _mappingRuleTranslator.GetTableName(_genericType);

            _builder.Append(string.Format("INSERT INTO {0} ", tableName));
            Visit(parameter);

            return(expression);
        }