1 //---------------------------------------------------------------------
2 // <copyright file="RelationshipNavigation.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
11 using System
.Collections
.Generic
;
12 using System
.Data
.Common
;
13 using System
.Globalization
;
15 using System
.Data
.Metadata
.Edm
;
17 namespace System
.Data
.Objects
.DataClasses
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
28 internal class RelationshipNavigation
35 /// Creates a navigation object with the given relationship
36 /// name, role name for the source and role name for the
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
;
54 _fromAccessor
= fromAccessor
;
55 _toAccessor
= toAccessor
;
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
;
71 private RelationshipNavigation _reverse
;
74 private NavigationPropertyAccessor _fromAccessor
;
77 private NavigationPropertyAccessor _toAccessor
;
84 /// Canonical-space relationship name.
86 internal string RelationshipName
90 return _relationshipName
;
95 /// Role name for the source of this navigation.
106 /// Role name for the destination of this navigation.
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.
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
;
138 /// The "reverse" version of this navigation.
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
);
156 /// Compares this instance to a given Navigation by their values.
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
)));
169 /// Returns a value-based hash code.
171 /// <returns>the hash value of this Navigation</returns>
172 public override int GetHashCode()
174 return this.RelationshipName
.GetHashCode();
182 /// ToString is provided to simplify debugging, etc.
184 public override string ToString()
186 return String
.Format(CultureInfo
.InvariantCulture
,
187 "RelationshipNavigation: ({0},{1},{2})",