public override string Parse(IDictionary <string, object> parameterDictionary, Expression expressionNode)
        {
            var sqlsb  = new StringBuilder();
            var newExp = expressionNode as NewExpression;

            if (_convertPropertyNameToDbName)
            {
                foreach (var memberAccessItem in newExp.Arguments)
                {
                    var memberAccessNode = SqlDbQueryExpressionFactory.GetNodeParser(memberAccessItem, ModelStrategy);

                    if (sqlsb.Length == 0)
                    {
                        sqlsb.Append(memberAccessNode.Parse(parameterDictionary, memberAccessItem));
                    }
                    else
                    {
                        sqlsb.Append(", ");
                        sqlsb.Append(memberAccessNode.Parse(parameterDictionary, memberAccessItem));
                    }
                }
            }
            else
            {
                foreach (var memberAccessItem in newExp.Arguments)
                {
                    SqlDbQueryExpressionNode memberAccessNode = new SqlDbQueryMemberAccessExpressionNode();
                    memberAccessNode.ModelStrategy = ModelStrategy;

                    if (sqlsb.Length == 0)
                    {
                        sqlsb.Append(memberAccessNode.Parse(parameterDictionary, memberAccessItem));
                    }
                    else
                    {
                        sqlsb.Append(", ");
                        sqlsb.Append(memberAccessNode.Parse(parameterDictionary, memberAccessItem));
                    }
                }
            }

            return(sqlsb.ToString());
        }
Ejemplo n.º 2
0
        public static IDbQueryExpressionNode GetNodeParser(Expression expression, IDbModelStrategy modelStrategy)
        {
            SqlDbQueryExpressionNode expressionNode = null;

            switch (expression.NodeType)
            {
            case ExpressionType.NotEqual:
                expressionNode = new SqlDbQueryNotEqualExpressionNode();
                break;

            case ExpressionType.Not:
                expressionNode = new SqlDbQueryNotExpressionNode();
                break;

            case ExpressionType.Equal:
                expressionNode = new SqlDbQueryEqualExpressionNode();
                break;

            case ExpressionType.GreaterThan:
            case ExpressionType.GreaterThanOrEqual:
                expressionNode = new SqlDbQueryGreaterThanExpressionNode();
                break;

            case ExpressionType.LessThan:
            case ExpressionType.LessThanOrEqual:
                expressionNode = new SqlDbQueryLessThanExpressionNode();
                break;

            case ExpressionType.Add:
            case ExpressionType.AddChecked:
                expressionNode = new SqlDbQueryAddExpressionNode();
                break;

            case ExpressionType.Subtract:
            case ExpressionType.SubtractChecked:
                expressionNode = new SqlDbQuerySubstractExpressionNode();
                break;

            case ExpressionType.Multiply:
            case ExpressionType.MultiplyChecked:
                expressionNode = new SqlDbQueryMultiplyExpressionNode();
                break;

            case ExpressionType.Divide:
                expressionNode = new SqlDbQueryDivideExpressionNode();
                break;

            case ExpressionType.MemberAccess:
                expressionNode = new SqlDbQueryMemberAccessExpressionNode();
                break;

            case ExpressionType.AndAlso:
                expressionNode = new SqlDbQueryAndAlsoExpressionNode();
                break;

            case ExpressionType.OrElse:
                expressionNode = new SqlDbQueryOrElseExpressionNode();
                break;

            case ExpressionType.Constant:
                expressionNode = new SqlDbQueryConstantExpressionNode();
                break;

            case ExpressionType.Call:
                expressionNode = new SqlDbQueryCallExpressionNode();
                break;

            case ExpressionType.Parameter:
                expressionNode = new SqlDbQueryParameterExpressionNode();
                break;

            case ExpressionType.Convert:
                expressionNode = new SqlDbQueryConvertExpressionNode();
                break;

            default:
                throw new NotSupportedException("ERROR_GIVEN_QUERY_EXPRESSION_TYPE_NOT_SUPPORTED");
            }

            expressionNode.ModelStrategy = modelStrategy;
            return(expressionNode);
        }