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.Diagnostics;
\r
29 using System.Linq.Expressions;
\r
31 using DbLinq.Data.Linq.Sugar.Expressions;
\r
33 namespace DbLinq.Data.Linq.Sugar.Expressions
\r
36 /// A table is a default table, or a joined table
\r
37 /// Different joins specify different tables
\r
39 [DebuggerDisplay("TableExpression {Name} (as {Alias})")]
\r
43 class TableExpression : MutableExpression
\r
45 public const ExpressionType ExpressionType = (ExpressionType)CustomExpressionType.Table;
\r
47 // Table idenfitication
\r
48 public string Name { get; private set; }
\r
50 // Join: if this table is related to another, the following informations are filled
\r
51 public Expression JoinExpression { get; private set; } // full information is here, ReferencedTable and Join could be (in theory) extracted from this
\r
52 public TableJoinType JoinType { get; private set; }
\r
53 public string JoinID { get; private set; }
\r
54 public TableExpression JoinedTable { get; private set; }
\r
56 public string Alias { get; set; }
\r
61 /// <param name="joinType"></param>
\r
62 /// <param name="joinedTable"></param>
\r
63 /// <param name="joinExpression"></param>
\r
64 public void Join(TableJoinType joinType, TableExpression joinedTable, Expression joinExpression)
\r
66 JoinExpression = joinExpression;
\r
67 JoinType = joinType;
\r
68 JoinedTable = joinedTable;
\r
74 /// <param name="joinType"></param>
\r
75 /// <param name="joinedTable"></param>
\r
76 /// <param name="joinExpression"></param>
\r
77 /// <param name="joinID"></param>
\r
78 public void Join(TableJoinType joinType, TableExpression joinedTable, Expression joinExpression, string joinID)
\r
80 Join(joinType, joinedTable, joinExpression);
\r
85 /// Set the table outer join, depending on the current table location
\r
86 /// Result can set the table to be left outer join or right outer join
\r
88 public void SetOuterJoin()
\r
90 // JoinExpression is non-null for associated table
\r
91 if (JoinExpression != null)
\r
92 JoinType |= TableJoinType.LeftOuter;
\r
94 JoinType |= TableJoinType.RightOuter;
\r
98 /// Ctor for associated table
\r
100 /// <param name="type">.NET type</param>
\r
101 /// <param name="name">Table base name</param>
\r
102 /// <param name="joinID"></param>
\r
103 public TableExpression(Type type, string name, string joinID)
\r
104 : base(ExpressionType, type)
\r
111 /// Ctor for default table
\r
113 /// <param name="type">.NET type</param>
\r
114 /// <param name="name">Table base name</param>
\r
115 public TableExpression(Type type, string name)
\r
116 : this(type, name, null)
\r
120 protected TableExpression(ExpressionType expressionType, TableExpression tableExpression)
\r
121 : base(expressionType, tableExpression.Type)
\r
123 Name = tableExpression.Name;
\r
126 public virtual bool IsEqualTo(TableExpression expression)
\r
128 return Name == expression.Name && JoinID == expression.JoinID;
\r