Updates referencesource to .NET 4.7
[mono-project.git] / mcs / class / referencesource / System.Data.Entity / System / Data / Objects / DataClasses / RelationshipNavigation.cs
blob82295b74317920bc7150a493ad64e6ceed203cb6
1 //---------------------------------------------------------------------
2 // <copyright file="RelationshipNavigation.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 // </copyright>
5 //
6 // @owner Microsoft
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
10 using System;
11 using System.Collections.Generic;
12 using System.Data.Common;
13 using System.Globalization;
14 using System.Text;
15 using System.Data.Metadata.Edm;
17 namespace System.Data.Objects.DataClasses
19 /// <summary>
20 /// This class describes a relationship navigation from the
21 /// navigation property on one entity to another entity. It is
22 /// used throughout the collections and refs system to describe a
23 /// relationship and to connect from the navigation property on
24 /// one end of a relationship to the navigation property on the
25 /// other end.
26 /// </summary>
27 [Serializable]
28 internal class RelationshipNavigation
30 // ------------
31 // Constructors
32 // ------------
34 /// <summary>
35 /// Creates a navigation object with the given relationship
36 /// name, role name for the source and role name for the
37 /// destination.
38 /// </summary>
39 /// <param name="relationshipName">Canonical-space name of the relationship.</param>
40 /// <param name="from">Name of the role which is the source of the navigation.</param>
41 /// <param name="to">Name of the role which is the destination of the navigation.</param>
42 /// <param name="fromAccessor">The navigation property which is the source of the navigation.</param>
43 /// <param name="toAccessor">The navigation property which is the destination of the navigation.</param>
44 internal RelationshipNavigation(string relationshipName, string from, string to, NavigationPropertyAccessor fromAccessor, NavigationPropertyAccessor toAccessor)
46 EntityUtil.CheckStringArgument(relationshipName, "relationshipName");
47 EntityUtil.CheckStringArgument(from, "from");
48 EntityUtil.CheckStringArgument(to, "to");
50 _relationshipName = relationshipName;
51 _from = from;
52 _to = to;
54 _fromAccessor = fromAccessor;
55 _toAccessor = toAccessor;
58 // ------
59 // Fields
60 // ------
62 // The following fields are serialized. Adding or removing a serialized field is considered
63 // a breaking change. This includes changing the field type or field name of existing
64 // serialized fields. If you need to make this kind of change, it may be possible, but it
65 // will require some custom serialization/deserialization code.
66 private readonly string _relationshipName;
67 private readonly string _from;
68 private readonly string _to;
70 [NonSerialized]
71 private RelationshipNavigation _reverse;
73 [NonSerialized]
74 private NavigationPropertyAccessor _fromAccessor;
76 [NonSerialized]
77 private NavigationPropertyAccessor _toAccessor;
79 // ----------
80 // Properties
81 // ----------
83 /// <summary>
84 /// Canonical-space relationship name.
85 /// </summary>
86 internal string RelationshipName
88 get
90 return _relationshipName;
94 /// <summary>
95 /// Role name for the source of this navigation.
96 /// </summary>
97 internal string From
99 get
101 return _from;
105 /// <summary>
106 /// Role name for the destination of this navigation.
107 /// </summary>
108 internal string To
112 return _to;
116 /// <summary>
117 /// Navigation property name for the destination of this navigation.
118 /// NOTE: There is not a FromPropertyAccessor property on RelationshipNavigation because it is not currently accessed anywhere
119 /// It is only used to calculate the "reverse" RelationshipNavigation.
120 /// </summary>
121 internal NavigationPropertyAccessor ToPropertyAccessor
123 get { return _toAccessor; }
126 internal bool IsInitialized
128 get { return _toAccessor != null && _fromAccessor != null; }
131 internal void InitializeAccessors(NavigationPropertyAccessor fromAccessor, NavigationPropertyAccessor toAccessor)
133 _fromAccessor = fromAccessor;
134 _toAccessor = toAccessor;
137 /// <summary>
138 /// The "reverse" version of this navigation.
139 /// </summary>
140 internal RelationshipNavigation Reverse
144 if (_reverse == null || !_reverse.IsInitialized)
146 // the reverse relationship is exactly like this
147 // one but from & to are switched
148 _reverse = new RelationshipNavigation(_relationshipName, _to, _from, _toAccessor, _fromAccessor);
151 return _reverse;
155 /// <summary>
156 /// Compares this instance to a given Navigation by their values.
157 /// </summary>
158 public override bool Equals(object obj)
160 RelationshipNavigation compareTo = obj as RelationshipNavigation;
161 return ((this == compareTo)
162 || ((null != this) && (null != compareTo)
163 && (this.RelationshipName == compareTo.RelationshipName)
164 && (this.From == compareTo.From)
165 && (this.To == compareTo.To)));
168 /// <summary>
169 /// Returns a value-based hash code.
170 /// </summary>
171 /// <returns>the hash value of this Navigation</returns>
172 public override int GetHashCode()
174 return this.RelationshipName.GetHashCode();
177 // -------
178 // Methods
179 // -------
181 /// <summary>
182 /// ToString is provided to simplify debugging, etc.
183 /// </summary>
184 public override string ToString()
186 return String.Format(CultureInfo.InvariantCulture,
187 "RelationshipNavigation: ({0},{1},{2})",
188 _relationshipName,
189 _from,
190 _to);