5 // Copyright (c) 2007-2008 Jiri Moudry, Pascal Craponne
\r
7 // Permission is hereby granted, free of charge, to any person obtaining a copy
\r
8 // of this software and associated documentation files (the "Software"), to deal
\r
9 // in the Software without restriction, including without limitation the rights
\r
10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
11 // copies of the Software, and to permit persons to whom the Software is
\r
12 // furnished to do so, subject to the following conditions:
\r
14 // The above copyright notice and this permission notice shall be included in
\r
15 // all copies or substantial portions of the Software.
\r
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
28 using System.Collections.Generic;
\r
29 using System.Linq.Expressions;
\r
31 using System.Data.Linq.Sugar.Expressions;
\r
33 using DbLinq.Data.Linq.Sugar.Expressions;
\r
37 namespace System.Data.Linq.Sugar.Expressions
\r
39 namespace DbLinq.Data.Linq.Sugar.Expressions
\r
43 /// ScopeExpression describes a selection.
\r
44 /// It can be present at top-level or as subexpressions
\r
49 class SelectExpression : OperandsMutableExpression
\r
51 public const ExpressionType ExpressionType = (ExpressionType)CustomExpressionType.Scope;
\r
53 // Involved entities
\r
54 public IList<TableExpression> Tables { get; private set; }
\r
55 public IList<ColumnExpression> Columns { get; private set; }
\r
58 public string ExecuteMethodName { get; set; } // for Execute<> calls, this member is filled with the method name
\r
59 public LambdaExpression Reader { get; set; } // Func<IDataRecord,DataMapper,T> --> creates an object from data record
\r
60 public IList<Expression> Where { get; private set; }
\r
61 public IList<OrderByExpression> OrderBy { get; private set; }
\r
62 public IList<GroupExpression> Group { get; private set; }
\r
64 public Expression Offset { get; set; }
\r
65 public Expression Limit { get; set; }
\r
66 public Expression OffsetAndLimit { get; set; }
\r
68 // the following two clauses are used by expressions of same level, linked by a special operation (like "union")
\r
69 public SelectExpression NextSelectExpression;
\r
70 public SelectOperatorType NextSelectExpressionOperator;
\r
72 // Parent scope: we will climb up to find if we don't find the request table in the current scope
\r
73 public SelectExpression Parent { get; private set; }
\r
75 public SelectExpression()
\r
76 : base(ExpressionType, null, null)
\r
78 Tables = new List<TableExpression>();
\r
79 Columns = new List<ColumnExpression>();
\r
81 Where = new List<Expression>();
\r
82 OrderBy = new List<OrderByExpression>();
\r
83 Group = new List<GroupExpression>();
\r
86 public SelectExpression(SelectExpression parentSelectExpression)
\r
87 : base(ExpressionType, null, null)
\r
89 Parent = parentSelectExpression;
\r
90 // Tables and columns are empty, since the table/column lookup recurses to parentScopePiece
\r
91 Tables = new List<TableExpression>();
\r
92 Columns = new List<ColumnExpression>();
\r
94 Where = new List<Expression>();
\r
95 OrderBy = new List<OrderByExpression>();
\r
96 Group = new List<GroupExpression>();
\r
99 private SelectExpression(Type type, IList<Expression> operands)
\r
100 : base(ExpressionType, type, operands)
\r
104 protected override Expression Mutate2(IList<Expression> newOperands)
\r
107 if (newOperands.Count > 0)
\r
108 type = newOperands[0].Type;
\r
111 var scopeExpression = new SelectExpression(type, newOperands);
\r
112 scopeExpression.Tables = Tables;
\r
113 scopeExpression.Columns = Columns;
\r
114 scopeExpression.Where = Where;
\r
115 scopeExpression.OrderBy = OrderBy;
\r
116 scopeExpression.Group = Group;
\r
117 scopeExpression.Parent = Parent;
\r
118 scopeExpression.ExecuteMethodName = ExecuteMethodName;
\r
119 scopeExpression.Reader = Reader;
\r
120 scopeExpression.Limit = Limit;
\r
121 scopeExpression.Offset = Offset;
\r
122 scopeExpression.OffsetAndLimit = OffsetAndLimit;
\r
123 scopeExpression.NextSelectExpression = NextSelectExpression;
\r
124 scopeExpression.NextSelectExpressionOperator = NextSelectExpressionOperator;
\r
125 return scopeExpression;
\r