8ef29bd37f344d5fce866a8c2d697ffc22a92558
[mono.git] / mcs / class / referencesource / System.Data.Entity / System / Data / Mapping / StorageAssociationTypeMapping.cs
1 //---------------------------------------------------------------------
2 // <copyright file="StorageAssociationTypeMapping.cs" company="Microsoft">
3 //      Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //
6 // @owner  Microsoft, Microsoft
7 //---------------------------------------------------------------------
8
9 using System;
10 using System.Collections.Generic;
11 using System.Collections.ObjectModel;
12 using System.Text;
13 using System.Data.Metadata.Edm;
14
15 namespace System.Data.Mapping {
16     /// <summary>
17     /// Represents the Mapping metadata for an association type map in CS space.
18     /// </summary>
19     /// <example>
20     /// For Example if conceptually you could represent the CS MSL file as following
21     /// --Mapping 
22     ///   --EntityContainerMapping ( CNorthwind-->SNorthwind )
23     ///     --EntitySetMapping
24     ///       --EntityTypeMapping
25     ///         --MappingFragment
26     ///           --EntityKey
27     ///             --ScalarPropertyMap
28     ///           --ScalarPropertyMap
29     ///       --EntityTypeMapping
30     ///         --MappingFragment
31     ///           --EntityKey
32     ///             --ScalarPropertyMap
33     ///           --ComplexPropertyMap
34     ///             --ComplexTypeMap
35     ///               --ScalarPropertyMap
36     ///               --ScalarProperyMap
37     ///           --ScalarPropertyMap
38     ///     --AssociationSetMapping 
39     ///       --AssociationTypeMapping
40     ///         --MappingFragment
41     ///           --EndPropertyMap
42     ///             --ScalarPropertyMap
43     ///             --ScalarProperyMap
44     ///           --EndPropertyMap
45     ///             --ScalarPropertyMap
46     /// This class represents the metadata for all association Type map elements in the 
47     /// above example. Users can access the table mapping fragments under the 
48     /// association type mapping through this class.
49     /// </example>
50     internal class StorageAssociationTypeMapping : StorageTypeMapping {
51         #region Constructors
52         /// <summary>
53         /// Construct the new AssociationTypeMapping object.
54         /// </summary>
55         /// <param name="relation">Represents the Association Type metadata object</param>
56         /// <param name="setMapping">Set Mapping that contains this Type mapping </param>
57         internal StorageAssociationTypeMapping(AssociationType relation, StorageSetMapping setMapping)
58             : base(setMapping) {
59             this.m_relation = relation;
60         }
61         #endregion
62
63         #region Fields
64         /// <summary>
65         /// Type for which the mapping is represented.
66         /// </summary>
67         AssociationType m_relation;
68         #endregion
69
70         #region Properties
71         /// <summary>
72         /// The AssociationTypeType Metadata object for which the mapping is represented.
73         /// </summary>
74         internal AssociationType AssociationType
75         {
76             get {
77                 return this.m_relation;
78             }
79         }
80
81         /// <summary>
82         /// a list of TypeMetadata that this mapping holds true for.
83         /// Since Association types dont participate in Inheritance, This can only
84         /// be one type.
85         /// </summary>
86         internal override ReadOnlyCollection<EdmType> Types {
87             get {
88                 return new ReadOnlyCollection<EdmType>(new AssociationType[] { m_relation });
89             }
90         }
91
92         /// <summary>
93         /// a list of TypeMetadatas for which the mapping holds true for
94         /// not only the type specified but the sub-types of that type as well.
95         /// Since Association types dont participate in Inheritance, an Empty list 
96         /// is returned here.
97         /// </summary>
98         internal override ReadOnlyCollection<EdmType> IsOfTypes {
99             get {
100                 return new List<EdmType>().AsReadOnly();
101             }
102         }
103         #endregion
104
105         #region Methods
106         /// <summary>
107         /// This method is primarily for debugging purposes.
108         /// Will be removed shortly.
109         /// </summary>
110         /// <param name="index"></param>
111         internal override void Print(int index) {
112             StorageEntityContainerMapping.GetPrettyPrintString(ref index);
113             StringBuilder sb = new StringBuilder();
114             sb.Append("AssociationTypeMapping");
115             sb.Append("   ");
116             sb.Append("Type Name:");
117             sb.Append(this.m_relation.Name);
118             sb.Append("   ");
119             Console.WriteLine(sb.ToString());
120             foreach (StorageMappingFragment fragment in MappingFragments) {
121                 fragment.Print(index + 5);
122             }
123         }
124         #endregion
125     }
126 }