private string ParseSelectorToColumn(DbQueryColumnClause <TModel> expression)
        {
            var exp = expression.ColumExpression;

            // check expression type is "New Expression" or "Parameter Expression"
            if (exp.Body is NewExpression)
            {
                var newExpNode = new SqlDbQueryNewExpressionRenderColumnsNode();
                newExpNode.ModelStrategy = _modelStrategy;
                return(newExpNode.Parse(_parameterDictionary, exp.Body));
            }

            if (exp.Body is UnaryExpression)
            {
                var paramNode = SqlDbQueryExpressionFactory.GetNodeParser(exp.Body, _modelStrategy);
                return(paramNode.Parse(_parameterDictionary, exp.Body));
            }

            if (exp.Body is ParameterExpression)
            {
                var paramNode = new SqlDbQueryParameterExpressionRenderColumnsNode();
                paramNode.ModelStrategy = _modelStrategy;
                return(paramNode.Parse(_parameterDictionary, exp.Body));
            }

            throw new NotSupportedException("Not supported expression type.");
        }
Esempio n. 2
0
 private string ParseSelectorToColumns <TModel>(Expression <Func <TModel, object> > selector)
 {
     // check expression type is "New Expression" or "Parameter Expression"
     if (selector.Body is NewExpression)
     {
         var newExpNode = new SqlDbQueryNewExpressionRenderColumnsNode();
         newExpNode.ModelStrategy = _modelStrategy;
         return(newExpNode.Parse(_parameterDictionary, selector.Body));
     }
     else if (selector.Body is UnaryExpression)
     {
         var paramNode = SqlDbQueryExpressionFactory.GetNodeParser(selector.Body, _modelStrategy);
         return(paramNode.Parse(_parameterDictionary, selector.Body));
     }
     else if (selector.Body is ParameterExpression)
     {
         var paramNode = new SqlDbQueryParameterExpressionRenderColumnsNode();
         paramNode.ModelStrategy = _modelStrategy;
         return(paramNode.Parse(_parameterDictionary, selector.Body));
     }
     else
     {
         throw new DbEnvironmentException(
                   "ERROR_EXPRESSION_NOT_SUPPORTED");
     }
 }
        private string ParseGroupByColumns(IEnumerable <DbQueryGroupByClause <TModel> > groupBySelectors)
        {
            if (groupBySelectors == null || !groupBySelectors.Any())
            {
                return(string.Empty);
            }

            var groupByColumnsBuilder = new StringBuilder();

            foreach (var groupBySelector in groupBySelectors)
            {
                var groupByClause = groupBySelector.Clause;

                // check expression type is "New Expression" or "Parameter Expression"
                if (groupByClause.Body is NewExpression)
                {
                    throw new NotSupportedException("ERROR_GROUP_BY_NOT_SUPPORT_NEW_EXPRESSION");
                }
                else if (groupByClause.Body is UnaryExpression)
                {
                    var paramNode = SqlDbQueryExpressionFactory.GetNodeParser(groupByClause.Body, _modelStrategy);

                    var name = paramNode.Parse(_parameterDictionary, groupByClause.Body);

                    if (groupByColumnsBuilder.Length > 0)
                    {
                        groupByColumnsBuilder.Append(", " + name);
                    }
                    else
                    {
                        groupByColumnsBuilder.Append(name);
                    }
                }
                else if (groupByClause.Body is ParameterExpression)
                {
                    var paramNode = new SqlDbQueryParameterExpressionRenderColumnsNode();
                    paramNode.ModelStrategy = _modelStrategy;
                    var name = paramNode.Parse(_parameterDictionary, groupByClause.Body);

                    if (groupByColumnsBuilder.Length > 0)
                    {
                        groupByColumnsBuilder.Append(", " + name);
                    }
                    else
                    {
                        groupByColumnsBuilder.Append(name);
                    }
                }
                else
                {
                    throw new DbEnvironmentException(
                              "ERROR_EXPRESSION_NOT_SUPPORTED");
                }
            }

            return(groupByColumnsBuilder.ToString());
        }