1 //---------------------------------------------------------------------
2 // <copyright file="StorageEntityTypeMapping.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
12 using System.Collections.Generic;
13 using System.Collections.ObjectModel;
15 using System.Data.Metadata.Edm;
17 namespace System.Data.Mapping {
19 /// Mapping metadata for Entity type.
20 /// If an EntitySet represents entities of more than one type, than we will have
21 /// more than one EntityTypeMapping for an EntitySet( For ex : if
22 /// PersonSet Entity extent represents entities of types Person and Customer,
23 /// than we will have two EntityType Mappings under mapping for PersonSet).
26 /// For Example if conceptually you could represent the CS MSL file as following
28 /// --EntityContainerMapping ( CNorthwind-->SNorthwind )
29 /// --EntitySetMapping
30 /// --EntityTypeMapping
33 /// --ScalarPropertyMap
34 /// --ScalarPropertyMap
35 /// --EntityTypeMapping
38 /// --ScalarPropertyMap
39 /// --ComplexPropertyMap
40 /// --ScalarPropertyMap
41 /// --ScalarProperyMap
42 /// --ScalarPropertyMap
43 /// --AssociationSetMapping
44 /// --AssociationTypeMapping
47 /// --ScalarPropertyMap
48 /// --ScalarProperyMap
50 /// --ScalarPropertyMap
51 /// This class represents the metadata for all entity Type map elements in the
52 /// above example. Users can access the table mapping fragments under the
53 /// entity type mapping through this class.
56 internal class StorageEntityTypeMapping : StorageTypeMapping {
59 /// Construct the new EntityTypeMapping object.
61 /// <param name="setMapping">Set Mapping that contains this Type mapping </param>
62 internal StorageEntityTypeMapping(StorageSetMapping setMapping)
69 /// Types for which the mapping holds true for.
71 private Dictionary<string, EdmType> m_entityTypes = new Dictionary<string, EdmType>(StringComparer.Ordinal);
73 /// Types for which the mapping holds true for not only the type specified but the sub-types of that type as well.
75 private Dictionary<string, EdmType> m_isOfEntityTypes = new Dictionary<string, EdmType>(StringComparer.Ordinal);
80 /// a list of TypeMetadata that this mapping holds true for.
82 internal override ReadOnlyCollection<EdmType> Types {
84 return new List<EdmType>(m_entityTypes.Values).AsReadOnly();
89 /// a list of TypeMetadatas for which the mapping holds true for
90 /// not only the type specified but the sub-types of that type as well.
92 internal override ReadOnlyCollection<EdmType> IsOfTypes {
94 return new List<EdmType>(m_isOfEntityTypes.Values).AsReadOnly();
101 /// Add a Type to the list of types that this mapping is valid for
103 internal void AddType(EdmType type) {
104 this.m_entityTypes.Add(type.FullName, type);
108 /// Add a Type to the list of Is-Of types that this mapping is valid for
110 internal void AddIsOfType(EdmType type) {
111 this.m_isOfEntityTypes.Add(type.FullName, type);
114 internal EntityType GetContainerType(string memberName) {
115 foreach (EntityType type in m_entityTypes.Values) {
116 if (type.Properties.Contains(memberName))
122 foreach (EntityType type in m_isOfEntityTypes.Values)
124 if (type.Properties.Contains(memberName))
134 /// This method is primarily for debugging purposes.
135 /// Will be removed shortly.
137 /// <param name="index"></param>
138 internal override void Print(int index) {
139 StorageEntityContainerMapping.GetPrettyPrintString(ref index);
140 StringBuilder sb = new StringBuilder();
141 sb.Append("EntityTypeMapping");
143 foreach (EdmType type in m_entityTypes.Values) {
145 sb.Append(type.FullName);
148 foreach (EdmType type in m_isOfEntityTypes.Values) {
149 sb.Append("Is-Of Types:");
150 sb.Append(type.FullName);
154 Console.WriteLine(sb.ToString());
155 foreach (StorageMappingFragment fragment in MappingFragments) {
156 fragment.Print(index + 5);