Пример #1
0
 public WindowFunction(Identifier identifier, OrderByClause order, IEnumerable<IAliasedExpression> partition)
     : base(identifier)
 {
     OverOrder = order;
     if (partition != null)
         partitionBy = new List<IAliasedExpression>(partition);
 }
Пример #2
0
 public MethodCall(Identifier identifier, Expression[] parameters, Identifier anonIndentifier, Identifier indexIdentifier, Expression lambdaExpression)
 {
     this.identifier = identifier;
     this.parameters = parameters;
     this.anonIndentifier = anonIndentifier;
     this.indexIdentifier = indexIdentifier;
     this.lambdaExpression = lambdaExpression;
 }
Пример #3
0
        public virtual MethodCall Update(MethodCall m, Identifier target, Identifier methodName, Expression[] args)
        {
            if (target != m.AnonIdentifier || methodName != m.Identifier || args != m.Parameters)
            {
                return new MethodCall(methodName, (Expression[])args, m.AnonIdentifier, m.IndexIdentifier, m.LambdaExpression);

            }
            return m;
        }
Пример #4
0
 public JoinClause(string type, Identifier identifier, Expression inIdentifier, Expression on, Expression equals, Identifier into)
 {
     this.type = type;
     this.identifier = identifier;
     this.inIdentifier = inIdentifier;
     this.on = on;
     this.equals = equals;
     this.into = into;
 }
Пример #5
0
 public ColumnExpression(TableAlias alias, string columnName, string columnAlias)
     : base(alias)
 {
     if (columnName == AllColumns.Text)
         ColumnName = AllColumns;
     else
     {
         ColumnName = new Identifier(columnName);
         if (!string.IsNullOrEmpty(columnAlias))
             ColumnAlias = new Identifier(columnAlias);
     }
 }
Пример #6
0
        public override NLinq.Expressions.SelectOrGroupClause Visit(NLinq.Expressions.SelectClause expression)
        {
            if (expression.Expression.ExpressionType == NLinq.Expressions.ExpressionTypes.Identifier)
            {
                identifierToFind = (Identifier)expression.Expression;
                return expression;
            }

            //visitingSelect = true;
            base.Visit(expression);
            //visitingSelect = false;
            return expression;
        }
Пример #7
0
 public override NLinq.Expressions.Expression Visit(NLinq.Expressions.MemberExpression expression)
 {
     bool changeTempTarget = tempTarget == null;
     if (changeTempTarget)
     {
         tempTarget = target;
         tempIdentifier = Query.From.Identifier;
     }
     var result = base.Visit(expression);
     if (changeTempTarget)
     {
         tempTarget = null;
         tempIdentifier = null;
     }
     return result;
 }
Пример #8
0
 public override Expression Visit(Identifier identifier)
 {
     Model.Reference reference;
     if (!tempTarget.References.TryGetValue(identifier.Text, out reference))
         throw new KeyNotFoundException("The reference " + identifier.Text + " could not be found on type " + tempTarget.Type);
     tempTarget = reference.Target;
     if (reference.Cardinality.IsMany)
     {
         tempIdentifier = new Identifier("e" + Query.QueryBody.Clauses.Count);
         Query.QueryBody.Clauses.Add(new FromClause(reference.Target.Type, tempIdentifier, new MemberExpression(new Identifier(reference.Name), ((SelectClause)Query.QueryBody.SelectOrGroup).Expression)));
         ((SelectClause)Query.QueryBody.SelectOrGroup).Expression = tempIdentifier;
     }
     else
     {
         ((SelectClause)Query.QueryBody.SelectOrGroup).Expression = new MemberExpression(new Identifier(reference.Name), ((SelectClause)Query.QueryBody.SelectOrGroup));
     }
     return base.Visit(identifier);
 }
Пример #9
0
 public MethodCall(Identifier identifier, Expression[] parameters)
 {
     this.identifier = identifier;
     this.parameters = parameters;
 }
Пример #10
0
 public DateAdd(Identifier identifier, Expression expression, Expression result)
     : base(DateAddIdentifier, identifier, expression, result)
 {
 }
Пример #11
0
            public AggreggateWindowFunction(Identifier identifier, OrderByClause order, IEnumerable<IAliasedExpression> partition)
                : base(identifier, order, partition)
            {

            }
Пример #12
0
 public MethodCall(Expression target, Identifier methodName, Expression[] parameters)
 {
     this.Target = target;
     this.MethodName = methodName;
     Parameters = parameters;
 }
Пример #13
0
 public DatePart(Identifier part, Expression expressionToCast)
     : base(DatePartIdentifier, new Expression[] { part, expressionToCast })
 {
 }
Пример #14
0
 public PropertyReferenceExpression(AliasedExpression target, Identifier propertyName)
     : base(target)
 {
     this.PropertyName = propertyName;
 }
Пример #15
0
 public Function(TableAlias alias, Identifier identifier, params Expression[] parameters)
     : base(alias)
 {
     this.MethodName = identifier;
     this.Parameters = parameters;
 }
Пример #16
0
 public ColumnExpression(TableAlias alias, Identifier columnName)
     : this(alias, columnName, null)
 {
 }
Пример #17
0
 public ColumnExpression(TableAlias alias, Identifier columnName, DbType type)
     : base(alias)
 {
     ColumnName = columnName;
     Type = type;
 }
Пример #18
0
 public QueryContinuation(Identifier identifier, QueryBody queryBody)
 {
     this.identifier = identifier;
     this.queryBody = queryBody;
 }
Пример #19
0
 public ComplexColumnExpression(TableAlias alias, Expression innerExpression, Identifier columnAlias)
     : base(alias, null, columnAlias)
 {
     Expression = innerExpression;
 }
Пример #20
0
 public override QueryBodyClause Visit(FromClause expression)
 {
     if (expression.Type == target.Type && targetIdentifier == null)
         targetIdentifier = expression.Identifier;
     return base.Visit(expression);
 }
Пример #21
0
 public virtual AnonymousParameter Update(AnonymousParameter original, Identifier identifier, Expression expression)
 {
     if (original.Expression != expression || original.Identifier != identifier)
         return new AnonymousParameter(identifier, expression);
     return original;
 }
Пример #22
0
 public LetClause(Identifier left, Expression right)
 {
     this.left = left;
     this.right = right;
 }
Пример #23
0
 public Aggregate(TableAlias alias, Identifier methodName, params Expression[] expression)
     : base(alias, methodName, expression)
 {
 }
Пример #24
0
 public Aggregate(Identifier methodName, params Expression[] expression)
     : base(methodName, expression)
 {
 }
Пример #25
0
 public ColumnExpression(TableAlias alias, Identifier columnName, Identifier columnAlias)
     : base(alias)
 {
     ColumnName = columnName;
     ColumnAlias = columnAlias;
 }
Пример #26
0
 public FromClause(string type, Identifier identifier, Expression expression)
 {
     this.type = type;
     this.identifier = identifier;
     this.expression = expression;
 }
Пример #27
0
        public NLinq.Expressions.Expression Visit(MethodCallExpression call)
        {
            if (call.Method.IsStatic && (call.Method.DeclaringType == typeof(Enumerable) || call.Method.DeclaringType == typeof(Queryable)) || call.Method.DeclaringType == typeof(ContextExtensions))
            {
                NLinq.Expressions.Expression subExpression = Visit(call.Arguments[0]);
                switch (call.Method.Name)
                {
                    case "Skip":
                    case "Take":
                        if (tree == null)
                        {
                            if (subExpression == null)
                                subExpression = new QueryExpression(from, new QueryBody(clauses, new SelectClause(identifiers["#First"]), null));
                            tree = new NLINQ.MemberExpression(new MethodCall(call.Method.Name, Visit(call.Arguments[1])), subExpression);
                        }
                        else
                            tree = new NLINQ.MemberExpression(new MethodCall(call.Method.Name, Visit(call.Arguments[1])), tree);
                        return tree;
                    case "Cast":
                        return subExpression;
                    case "FirstOrDefault":
                    case "LastOrDefault":
                    case "Last":
                    case "First":
                        string methodName = call.Method.Name;
                        if (call.Method.Name.EndsWith("OrDefault"))
                            methodName = methodName.Substring(0, call.Method.Name.Length - 9);
                        if (tree == null)
                        {
                            if (subExpression == null)
                                subExpression = new QueryExpression(from, new QueryBody(clauses, new SelectClause(identifiers["#First"]), null));
                            tree = new NLINQ.MemberExpression(new MethodCall(new Identifier(methodName)), subExpression);
                        }
                        else
                            tree = new NLINQ.MemberExpression(new MethodCall(new Identifier(methodName)), tree);
                        break;
                    case "Select":
                        SelectOrGroupClause select = new SelectClause(Visit(call.Arguments[1]));
                        tree = new QueryExpression(from, new QueryBody(clauses, select, null));
                        identifiers["#First"].Text = "e" + identifiers["#First"].GetHashCode();
                        identifiers.Clear();
                        identifiers["#First"] = new Identifier("e0");
                        clauses = new ClauseList();
                        from = new FromClause(null, identifiers["#First"], tree);
                        return tree;
                    case "SelectMany":
                        //Select the result of the join (a load reference)
                        FromClause from2 = null;
                        Identifier newElement = null;
                        select = null;

                        if (call.Arguments.Count == 2)
                            newElement = new Identifier("e1");
                        if (call.Arguments.Count == 3)
                            newElement = new Identifier(((System.Linq.Expressions.LambdaExpression)((System.Linq.Expressions.UnaryExpression)call.Arguments[2]).Operand).Parameters[1].Name);

                        from2 = new FromClause(call.Method.GetGenericArguments()[1].FullName, newElement, Visit(call.Arguments[1]));

                        if (call.Arguments.Count == 2)
                        {
                            //System.Linq.Expressions.LambdaExpression lambda = ((System.Linq.Expressions.LambdaExpression)((System.Linq.Expressions.UnaryExpression)call.Arguments[1]).Operand);
                            identifiers["#First"].Text = "e" + identifiers["#First"].GetHashCode();

                            //newElement = new Identifier("e0");
                            identifiers.Clear();
                            newElement.Text = "e0";
                            identifiers.Add("#First", newElement);
                            identifiers.Add(newElement.Text, newElement);
                            select = new SelectClause(newElement);
                        }

                        //Select a property of the select many
                        if (call.Arguments.Count == 3)
                        {
                            //newElement = new Identifier(((System.Linq.Expressions.LambdaExpression)((System.Linq.Expressions.UnaryExpression)call.Arguments[2]).Operand).Parameters[1].Name);
                            identifiers.Add(newElement.Text, newElement);
                            Identifier src = new Identifier(((System.Linq.Expressions.LambdaExpression)((System.Linq.Expressions.UnaryExpression)call.Arguments[2]).Operand).Parameters[0].Name);
                            if (!identifiers.ContainsKey(src.Text))
                                identifiers.Add(src.Text, identifiers["#First"]);
                            select = new SelectClause(Visit(((System.Linq.Expressions.LambdaExpression)((System.Linq.Expressions.UnaryExpression)call.Arguments[2]).Operand).Body));
                            if (((SelectClause)select).Expression == null)
                                select = null;
                        }
                        if (call.Arguments.Count > 3)
                            throw new NotSupportedException();
                        //from2 = new FromClause(call.Method.GetGenericArguments()[1].FullName, newElement, Visit(((System.Linq.Expressions.LambdaExpression)((System.Linq.Expressions.UnaryExpression)call.Arguments[1]).Operand).Body));
                        clauses.Add(from2);
                        tree = new QueryExpression(from, new QueryBody(clauses, select, null));
                        break;
                    case "Avg":
                    case "Sum":
                        if (subExpression == null)
                            subExpression = new QueryExpression(from, new QueryBody(clauses, new SelectClause(identifiers["#First"]), null));
                        tree = new NLINQ.MemberExpression(new MethodCall(new Identifier(call.Method.Name)), subExpression);
                        return tree;
                    case "Count":
                    case "Any":
                        if (call.Arguments.Count > 1)
                        {
                            if (subExpression != null)
                            {
                                var param = ((System.Linq.Expressions.LambdaExpression)call.Arguments[1]).Parameters[0];
                                var paramIdent = new Identifier(param.Name);
                                identifiers.Add(param.Name, paramIdent);
                                subExpression = new QueryExpression(new FromClause(param.Type.FullName, paramIdent, subExpression), new QueryBody(new ClauseList(new List<QueryBodyClause>() { new WhereClause(Visit(call.Arguments[1])) }), new SelectClause(paramIdent), null));
                            }
                            else
                                clauses.Add(new WhereClause(Visit(call.Arguments[1])));
                        }
                        if (subExpression == null)
                            subExpression = new QueryExpression(from, new QueryBody(clauses, new SelectClause(identifiers["#First"]), null));
                        tree = new NLINQ.MemberExpression(new MethodCall(new Identifier(call.Method.Name)), subExpression);
                        return tree;
                    case "Intersect":
                        break;
                    case "Where":
                        clauses.Add(new WhereClause(Visit(call.Arguments[1])));
                        tree = null;
                        if (from == null)
                            from = new FromClause(null, identifiers["#First"], subExpression);
                        break;
                    case "OrderBy":
                        NLINQ.Expression m = Visit(call.Arguments[1]);
                        clauses.Add(new OrderByClause(new OrderByCriteria(m, true)));
                        break;
                    case "ThenBy":
                        break;
                    case "Infer":
                        var inferQuery = new QueryTranslator(from.Type);
                        var result = inferQuery.Visit(call.Arguments[1]);
                        var first = inferQuery.identifiers["#First"];
                        NLINQ.MemberExpression me = (NLINQ.MemberExpression)result;
                        while (me.Previous != first)
                            me = (NLINQ.MemberExpression)me.Previous;
                        me.Previous = null;
                        if (inferQuery.tree != null)
                            result = inferQuery.tree;
                        InferredRelationShips.Add(result.ToString());
                        tree = subExpression;
                        return subExpression;
                }
            }
            if (call.Method.DeclaringType == typeof(string) || call.Method.DeclaringType == typeof(DateTime))
            {
                NLinq.Expressions.Expression source = Visit(call.Object);
                List<NLinq.Expressions.Expression> parameters = new List<NLinq.Expressions.Expression>();
                foreach (var arg in call.Arguments)
                {
                    var param = Visit(arg);
                    if (param != null)
                        parameters.Add(param);
                }
                return new NLinq.Expressions.MemberExpression(
                    new NLinq.Expressions.MethodCall(new NLinq.Expressions.Identifier(call.Method.Name), parameters.ToArray()),
                    source);
            }
            return null;
        }
Пример #28
0
        public NLinq.Expressions.Expression Visit(System.Linq.Expressions.LambdaExpression expression)
        {
            List<string> identifiers = new List<string>();
            foreach (ParameterExpression param in expression.Parameters)
            {
                if (!string.IsNullOrEmpty(param.Name))
                    identifiers.Add(param.Name);

                Identifier identifier;

                if (this.identifiers["#First"].Text == "e0")
                {
                    this.identifiers["#First"].Text = param.Name;
                    this.identifiers.Add(param.Name, this.identifiers["#First"]);
                    identifiers.Remove(param.Name);
                }
                else if (!this.identifiers.TryGetValue(param.Name, out identifier))
                {
                    identifier = new Identifier(param.Name);
                    if (string.IsNullOrEmpty(param.Name))
                        identifier.Text = "e" + param.GetHashCode();
                    this.identifiers.Add(param.Name, identifier);
                }
            }
            if (from == null)
                Visit(expression.Parameters[0]);
            NLinq.Expressions.Expression result = Visit(expression.Body);
            return result;
        }
Пример #29
0
 public PropertyReferenceExpression(TableAlias alias, AliasedExpression target, Identifier propertyName)
     : base(alias, target)
 {
     this.PropertyName = propertyName;
 }
Пример #30
0
 public Function(Identifier identifier, params Expression[] parameters)
     : this(null, identifier, parameters)
 {
 }