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

RelationshipNavigation.cs « DataClasses « Objects « 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: 82295b74317920bc7150a493ad64e6ceed203cb6 (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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
//---------------------------------------------------------------------
// <copyright file="RelationshipNavigation.cs" company="Microsoft">
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//
// @owner       Microsoft
// @backupOwner Microsoft
//---------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Globalization;
using System.Text;
using System.Data.Metadata.Edm;

namespace System.Data.Objects.DataClasses
{
    /// <summary>
    /// This class describes a relationship navigation from the
    /// navigation property on one entity to another entity.  It is
    /// used throughout the collections and refs system to describe a
    /// relationship and to connect from the navigation property on
    /// one end of a relationship to the navigation property on the
    /// other end.
    /// </summary>
    [Serializable]
    internal class RelationshipNavigation
    {
        // ------------
        // Constructors
        // ------------

        /// <summary>
        /// Creates a navigation object with the given relationship
        /// name, role name for the source and role name for the
        /// destination.
        /// </summary>
        /// <param name="relationshipName">Canonical-space name of the relationship.</param>
        /// <param name="from">Name of the role which is the source of the navigation.</param>
        /// <param name="to">Name of the role which is the destination of the navigation.</param>
        /// <param name="fromAccessor">The navigation property which is the source of the navigation.</param>
        /// <param name="toAccessor">The navigation property which is the destination of the navigation.</param>
        internal RelationshipNavigation(string relationshipName, string from, string to, NavigationPropertyAccessor fromAccessor, NavigationPropertyAccessor toAccessor)
        {
            EntityUtil.CheckStringArgument(relationshipName, "relationshipName");
            EntityUtil.CheckStringArgument(from, "from");
            EntityUtil.CheckStringArgument(to, "to");
            
            _relationshipName = relationshipName;
            _from = from;
            _to = to;

            _fromAccessor = fromAccessor;
            _toAccessor = toAccessor;
        }
    
        // ------
        // Fields
        // ------

        // The following fields are serialized.  Adding or removing a serialized field is considered
        // a breaking change.  This includes changing the field type or field name of existing
        // serialized fields. If you need to make this kind of change, it may be possible, but it
        // will require some custom serialization/deserialization code.
        private readonly string _relationshipName;
        private readonly string _from;
        private readonly string _to;

        [NonSerialized]
        private RelationshipNavigation _reverse;

        [NonSerialized]
        private NavigationPropertyAccessor _fromAccessor;

        [NonSerialized]
        private NavigationPropertyAccessor _toAccessor;

        // ----------
        // Properties
        // ----------

        /// <summary>
        /// Canonical-space relationship name.
        /// </summary>        
        internal string RelationshipName
        {
            get
            {
                return _relationshipName;
            }
        }

        /// <summary>
        /// Role name for the source of this navigation.
        /// </summary>        
        internal string From
        {
            get
            {
                return _from;
            }
        }

        /// <summary>
        /// Role name for the destination of this navigation.
        /// </summary>        
        internal string To
        {
            get
            {
                return _to;
            }
        }

        /// <summary>
        /// Navigation property name for the destination of this navigation.
        /// NOTE: There is not a FromPropertyAccessor property on RelationshipNavigation because it is not currently accessed anywhere
        ///       It is only used to calculate the "reverse" RelationshipNavigation.
        /// </summary>        
        internal NavigationPropertyAccessor ToPropertyAccessor
        {
            get { return _toAccessor; }
        }

        internal bool IsInitialized
        {
            get { return _toAccessor != null && _fromAccessor != null; }
        }

        internal void InitializeAccessors(NavigationPropertyAccessor fromAccessor, NavigationPropertyAccessor toAccessor)
        {
            _fromAccessor = fromAccessor;
            _toAccessor = toAccessor;
        }
        
        /// <summary>
        /// The "reverse" version of this navigation.
        /// </summary>        
        internal RelationshipNavigation Reverse
        {
            get
            {
                if (_reverse == null || !_reverse.IsInitialized)
                {
                    // the reverse relationship is exactly like this
                    // one but from & to are switched
                    _reverse = new RelationshipNavigation(_relationshipName, _to, _from, _toAccessor, _fromAccessor);
                }
                
                return _reverse;
            }
        }

        /// <summary>
        /// Compares this instance to a given Navigation by their values.
        /// </summary>        
        public override bool Equals(object obj)
        {
                RelationshipNavigation compareTo = obj as RelationshipNavigation;
                return ((this == compareTo)
                        || ((null != this) && (null != compareTo)
                            && (this.RelationshipName == compareTo.RelationshipName)
                            && (this.From == compareTo.From)
                            && (this.To == compareTo.To)));
        }
        
        /// <summary>
        /// Returns a value-based hash code.
        /// </summary>
        /// <returns>the hash value of this Navigation</returns>
        public override int GetHashCode()
        {
                return this.RelationshipName.GetHashCode();
        }
        
        // -------
        // Methods
        // -------

        /// <summary>
        /// ToString is provided to simplify debugging, etc.
        /// </summary>
        public override string ToString()
        {
            return String.Format(CultureInfo.InvariantCulture,
                                 "RelationshipNavigation: ({0},{1},{2})",
                                 _relationshipName,
                                 _from,
                                 _to);
        }        
    }
}