public ConstantNode(ConstantExpression expression, SqlNode parent) : base(parent)
        {
            Value = expression.Value;
            var parameter = Parent.GetParameterFor(expression.Value);

            ParameterName = parameter.ParameterName;
        }
Exemple #2
0
        public SqlParameterNode(MemberExpression expression, SqlNode parent) : base(parent)
        {
            Value = ExpressionValueRetreiver.GetValueFrom(expression);
            var parameter = GetParameterFor(Value);

            ParameterName = parameter.ParameterName;
        }
 public MethodNode(MethodCallExpression expression, SqlNode parent, IMethodTranslator translator) : base(parent)
 {
     MethodName  = expression.Method.Name;
     Object      = For(expression.Object);
     Arguments   = expression.Arguments.Select(For).ToList();
     _translator = translator;
 }
Exemple #4
0
        public NewSimpleValueNode(NewExpression expression, SqlNode parent) : base(parent)
        {
            var arguments = GetArgumentValues(expression).ToArray();

            Value = expression.Constructor.Invoke(arguments);
            var parameter = Parent.GetParameterFor(Value);

            ParameterName = parameter.ParameterName;
        }
Exemple #5
0
        public ColumnNode(MemberExpression expression, SqlNode parent) : base(parent)
        {
            var parameter = expression.Expression as ParameterExpression;

            if (parameter == null)
            {
                throw new InvalidOperationException(string.Format("Cannot select column for a parameterless MemberExpression."));
            }
            Name  = expression.Member.Name;
            Alias = GetAliasFor(parameter.Name);
        }
        public ColumnSelectorNode(MemberInitExpression expression, SqlNode parent) : base(parent)
        {
            var members         = expression.Bindings.Select(b => b.Member).ToArray();
            var otherProperties =
                expression.Type.GetProperties()
                .Where(p => p.PropertyType.IsValueOrString() && !members.Contains(p));
            var otherFields =
                expression.Type.GetFields()
                .Where(f => f.FieldType.IsValueOrString() && !members.Contains(f));

            Selectors = expression.Bindings
                        .Select(b => ColumnSelectorFor((dynamic)b))
                        .Concat(otherProperties.Select(m => new ColumnSelector(m, Expression.Constant(m.PropertyType.GetDefaultValue().ToDbValue()), this)))
                        .Concat(otherFields.Select(m => new ColumnSelector(m, Expression.Constant(m.FieldType.GetDefaultValue().ToDbValue()), this)))
                        .Cast <ColumnSelector>()
                        .ToList();
        }
        public ColumnSelectorNode(NewExpression expression, SqlNode parent) : base(parent)
        {
//            if (expression.Arguments.Count != expression.Members.Count)
//            {
//                throw new InvalidOperationException(string.Format("Sorry, I can't figure out how to solve arguments ({0}) into ({1})",
//                    string.Join(", ", expression.Arguments.Select(a => a.Type)),
//                    string.Join(", ", expression.Members.Select(m => m.Name))));
//            }

            var otherProperties =
                expression.Type.GetProperties()
                .Where(p => p.PropertyType.IsValueOrString() && !expression.Members.Contains(p));
            var otherFields =
                expression.Type.GetFields()
                .Where(f => f.FieldType.IsValueOrString() && !expression.Members.Contains(f));

            Selectors = expression.Members
                        .Select((m, ii) => new ColumnSelector(m, expression.Arguments[ii], this))
                        .Concat(otherProperties.Select(m => new ColumnSelector(m, Expression.Constant(m.PropertyType.GetDefaultValue().ToDbValue()), this)))
                        .Concat(otherFields.Select(m => new ColumnSelector(m, Expression.Constant(m.FieldType.GetDefaultValue().ToDbValue()), this)))
                        .ToList();
        }
Exemple #8
0
 public ColumnSelector(MemberInfo member, Expression argument, SqlNode parent) : base(parent)
 {
     Alias    = member.Name;
     Argument = For(argument);
 }
Exemple #9
0
 public AliasNode(ParameterExpression expression, SqlNode parent) : base(parent)
 {
     Name  = expression.Name;
     Alias = GetAliasFor(expression.Name);
 }
Exemple #10
0
 public LambdaNode(LambdaExpression expression, SqlNode parent) : base(parent)
 {
     Parameters = expression.Parameters.Select(For).ToList();
     Body       = For(expression.Body);
 }
Exemple #11
0
 protected SqlNode(SqlNode parent)
 {
     Parent = parent;
 }
Exemple #12
0
 public BinaryNode(BinaryExpression expression, SqlNode parent) : base(parent)
 {
     Left     = For(expression.Left);
     Operator = SqlOperator.For(expression.NodeType);
     Right    = For(expression.Right);
 }