1 //---------------------------------------------------------------------
2 // <copyright file="JoinSymbol.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
11 using System.Collections.Generic;
12 using System.Diagnostics;
15 using System.Data.SqlClient;
16 using System.Data.Metadata.Edm;
17 using System.Data.Common.CommandTrees;
19 namespace System.Data.SqlClient.SqlGen
22 /// A Join symbol is a special kind of Symbol.
23 /// It has to carry additional information
24 /// <list type="bullet">
25 /// <item>ColumnList for the list of columns in the select clause if this
26 /// symbol represents a sql select statement. This is set by <see cref="SqlGenerator.AddDefaultColumns"/>. </item>
27 /// <item>ExtentList is the list of extents in the select clause.</item>
28 /// <item>FlattenedExtentList - if the Join has multiple extents flattened at the
29 /// top level, we need this information to ensure that extent aliases are renamed
30 /// correctly in <see cref="SqlSelectStatement.WriteSql"/></item>
31 /// <item>NameToExtent has all the extents in ExtentList as a dictionary.
32 /// This is used by <see cref="SqlGenerator.Visit(DbPropertyExpression)"/> to flatten
33 /// record accesses.</item>
34 /// <item>IsNestedJoin - is used to determine whether a JoinSymbol is an
35 /// ordinary join symbol, or one that has a corresponding SqlSelectStatement.</item>
38 /// All the lists are set exactly once, and then used for lookups/enumerated.
40 internal sealed class JoinSymbol : Symbol
42 private List<Symbol> columnList;
43 internal List<Symbol> ColumnList
47 if (null == columnList)
49 columnList = new List<Symbol>();
53 set { columnList = value; }
56 private List<Symbol> extentList;
57 internal List<Symbol> ExtentList
59 get { return extentList; }
62 private List<Symbol> flattenedExtentList;
63 internal List<Symbol> FlattenedExtentList
67 if (null == flattenedExtentList)
69 flattenedExtentList = new List<Symbol>();
71 return flattenedExtentList;
73 set { flattenedExtentList = value; }
76 private Dictionary<string, Symbol> nameToExtent;
77 internal Dictionary<string, Symbol> NameToExtent
79 get { return nameToExtent; }
82 private bool isNestedJoin;
83 internal bool IsNestedJoin
85 get { return isNestedJoin; }
86 set { isNestedJoin = value; }
89 public JoinSymbol(string name, TypeUsage type, List<Symbol> extents)
92 extentList = new List<Symbol>(extents.Count);
93 nameToExtent = new Dictionary<string, Symbol>(extents.Count, StringComparer.OrdinalIgnoreCase);
94 foreach (Symbol symbol in extents)
96 this.nameToExtent[symbol.Name] = symbol;
97 this.ExtentList.Add(symbol);