Welcome to mirror list, hosted at ThFree Co, Russian Federation.

StorageEntityTypeMapping.cs « Mapping « Data « System « System.Data.Entity « referencesource « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6ed006dca51199e7ef920a033e1373490c4330f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//---------------------------------------------------------------------
// <copyright file="StorageEntityTypeMapping.cs" company="Microsoft">
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//
// @owner       Microsoft
// @backupOwner Microsoft
//---------------------------------------------------------------------


using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Data.Metadata.Edm;

namespace System.Data.Mapping {
    /// <summary>
    /// Mapping metadata for Entity type.
    /// If an EntitySet represents entities of more than one type, than we will have
    /// more than one EntityTypeMapping for an EntitySet( For ex : if
    /// PersonSet Entity extent represents entities of types Person and Customer,
    /// than we will have two EntityType Mappings under mapping for PersonSet).
    /// </summary>
    /// <example>
    /// For Example if conceptually you could represent the CS MSL file as following
    /// --Mapping 
    ///   --EntityContainerMapping ( CNorthwind-->SNorthwind )
    ///     --EntitySetMapping
    ///       --EntityTypeMapping
    ///         --MappingFragment
    ///           --EntityKey
    ///             --ScalarPropertyMap
    ///           --ScalarPropertyMap
    ///       --EntityTypeMapping
    ///         --MappingFragment
    ///           --EntityKey
    ///             --ScalarPropertyMap
    ///           --ComplexPropertyMap
    ///             --ScalarPropertyMap
    ///             --ScalarProperyMap
    ///           --ScalarPropertyMap
    ///     --AssociationSetMapping 
    ///       --AssociationTypeMapping
    ///         --MappingFragment
    ///           --EndPropertyMap
    ///             --ScalarPropertyMap
    ///             --ScalarProperyMap
    ///           --EndPropertyMap
    ///             --ScalarPropertyMap
    /// This class represents the metadata for all entity Type map elements in the 
    /// above example. Users can access the table mapping fragments under the 
    /// entity type mapping through this class.
    /// </example>

    internal class StorageEntityTypeMapping : StorageTypeMapping {
        #region Constructors
        /// <summary>
        /// Construct the new EntityTypeMapping object.
        /// </summary>
        /// <param name="setMapping">Set Mapping that contains this Type mapping </param>
        internal StorageEntityTypeMapping(StorageSetMapping setMapping)
            : base(setMapping) {
        }
        #endregion

        #region Fields
        /// <summary>
        /// Types for which the mapping holds true for.
        /// </summary>
        private Dictionary<string, EdmType> m_entityTypes = new Dictionary<string, EdmType>(StringComparer.Ordinal);
        /// <summary>
        /// Types for which the mapping holds true for not only the type specified but the sub-types of that type as well.
        /// </summary>
        private Dictionary<string, EdmType> m_isOfEntityTypes = new Dictionary<string, EdmType>(StringComparer.Ordinal);
        #endregion

        #region Properties
        /// <summary>
        /// a list of TypeMetadata that this mapping holds true for.
        /// </summary>
        internal override ReadOnlyCollection<EdmType> Types {
            get {
                return new List<EdmType>(m_entityTypes.Values).AsReadOnly();
            }
        }

        /// <summary>
        /// a list of TypeMetadatas for which the mapping holds true for
        /// not only the type specified but the sub-types of that type as well.        
        /// </summary>
        internal override ReadOnlyCollection<EdmType> IsOfTypes {
            get {
                return new List<EdmType>(m_isOfEntityTypes.Values).AsReadOnly();
            }
        }
        #endregion

        #region Methods
        /// <summary>
        /// Add a Type to the list of types that this mapping is valid for
        /// </summary>
        internal void AddType(EdmType type) {
            this.m_entityTypes.Add(type.FullName, type);
        }

        /// <summary>
        /// Add a Type to the list of Is-Of types that this mapping is valid for
        /// </summary>
        internal void AddIsOfType(EdmType type) {
            this.m_isOfEntityTypes.Add(type.FullName, type);
        }

        internal EntityType GetContainerType(string memberName) {
            foreach (EntityType type in m_entityTypes.Values) {
                if (type.Properties.Contains(memberName))
                {
                    return type;
                }
            }

            foreach (EntityType type in m_isOfEntityTypes.Values)
            {
                if (type.Properties.Contains(memberName))
                {
                    return type;
                }
            }
            return null;
        }


        /// <summary>
        /// This method is primarily for debugging purposes.
        /// Will be removed shortly.
        /// </summary>
        /// <param name="index"></param>
        internal override void Print(int index) {
            StorageEntityContainerMapping.GetPrettyPrintString(ref index);
            StringBuilder sb = new StringBuilder();
            sb.Append("EntityTypeMapping");
            sb.Append("   ");
            foreach (EdmType type in m_entityTypes.Values) {
                sb.Append("Types:");
                sb.Append(type.FullName);
                sb.Append("   ");
            }
            foreach (EdmType type in m_isOfEntityTypes.Values) {
                sb.Append("Is-Of Types:");
                sb.Append(type.FullName);
                sb.Append("   ");
            }

            Console.WriteLine(sb.ToString());
            foreach (StorageMappingFragment fragment in MappingFragments) {
                fragment.Print(index + 5);
            }
        }
        #endregion
    }
}