Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / ndp / fx / src / DataEntity / System / Data / Objects / RelationshipWrapper.cs / 1 / RelationshipWrapper.cs
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Data.Metadata.Edm;
namespace System.Data.Objects
{
internal sealed class RelationshipWrapper : IEquatable
{
internal readonly AssociationSet AssociationSet;
internal readonly EntityKey Key0;
internal readonly EntityKey Key1;
internal RelationshipWrapper(AssociationSet extent, EntityKey key)
{
Debug.Assert(null != extent, "null RelationshipWrapper");
Debug.Assert(null != (object)key, "null key");
this.AssociationSet = extent;
this.Key0 = key;
this.Key1 = key;
}
internal RelationshipWrapper(RelationshipWrapper wrapper, int ordinal, EntityKey key)
{
Debug.Assert(null != wrapper, "null RelationshipWrapper");
Debug.Assert((uint)ordinal <= 1u, "ordinal out of range");
Debug.Assert(null != (object)key, "null key2");
this.AssociationSet = wrapper.AssociationSet;
this.Key0 = (0 == ordinal) ? key : wrapper.Key0;
this.Key1 = (0 == ordinal) ? wrapper.Key1 : key;
}
internal RelationshipWrapper(AssociationSet extent,
KeyValuePair roleAndKey1,
KeyValuePair roleAndKey2)
: this(extent, roleAndKey1.Key, roleAndKey1.Value, roleAndKey2.Key, roleAndKey2.Value)
{
}
internal RelationshipWrapper(AssociationSet extent,
string role0, EntityKey key0,
string role1, EntityKey key1)
{
Debug.Assert(null != extent, "null AssociationSet");
Debug.Assert(null != (object)key0, "null key0");
Debug.Assert(null != (object)key1, "null key1");
AssociationSet = extent;
Debug.Assert(extent.ElementType.AssociationEndMembers.Count == 2, "only 2 ends are supported");
// this assert is explictly commented out to show that the two are similar but different
// we should always use AssociationEndMembers, never CorrespondingAssociationEndMember
//Debug.Assert(AssociationSet.AssociationSetEnds.Count == 2, "only 2 set ends supported");
//Debug.Assert(extent.ElementType.AssociationEndMembers[0] == AssociationSet.AssociationSetEnds[0].CorrespondingAssociationEndMember, "should be same end member");
//Debug.Assert(extent.ElementType.AssociationEndMembers[1] == AssociationSet.AssociationSetEnds[1].CorrespondingAssociationEndMember, "should be same end member");
if (extent.ElementType.AssociationEndMembers[0].Name == role0)
{
Debug.Assert(extent.ElementType.AssociationEndMembers[1].Name == role1, "a)roleAndKey1 Name differs");
Key0 = key0;
Key1 = key1;
}
else
{
Debug.Assert(extent.ElementType.AssociationEndMembers[0].Name == role1, "b)roleAndKey1 Name differs");
Debug.Assert(extent.ElementType.AssociationEndMembers[1].Name == role0, "b)roleAndKey0 Name differs");
Key0 = key1;
Key1 = key0;
}
}
internal ReadOnlyMetadataCollection AssociationEndMembers
{
get { return this.AssociationSet.ElementType.AssociationEndMembers; }
}
internal AssociationEndMember GetAssociationEndMember(EntityKey key)
{
Debug.Assert(Key0 == key || Key1 == key, "didn't match a key");
return AssociationEndMembers[(Key0 != key) ? 1 : 0];
}
internal EntityKey GetOtherEntityKey(EntityKey key)
{
return ((Key0 == key) ? Key1 : ((Key1 == key) ? Key0 : null));
}
internal EntityKey GetEntityKey(int ordinal)
{
switch (ordinal)
{
case 0:
return Key0;
case 1:
return Key1;
default:
throw EntityUtil.ArgumentOutOfRange("ordinal");
}
}
public override int GetHashCode()
{
return this.AssociationSet.Name.GetHashCode() ^ (this.Key0.GetHashCode() + this.Key1.GetHashCode());
}
public override bool Equals(object obj)
{
return Equals(obj as RelationshipWrapper);
}
public bool Equals(RelationshipWrapper wrapper)
{
return (Object.ReferenceEquals(this, wrapper) ||
((null != wrapper) &&
Object.ReferenceEquals(this.AssociationSet, wrapper.AssociationSet) &&
this.Key0.Equals(wrapper.Key0) &&
this.Key1.Equals(wrapper.Key1)));
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Data.Metadata.Edm;
namespace System.Data.Objects
{
internal sealed class RelationshipWrapper : IEquatable
{
internal readonly AssociationSet AssociationSet;
internal readonly EntityKey Key0;
internal readonly EntityKey Key1;
internal RelationshipWrapper(AssociationSet extent, EntityKey key)
{
Debug.Assert(null != extent, "null RelationshipWrapper");
Debug.Assert(null != (object)key, "null key");
this.AssociationSet = extent;
this.Key0 = key;
this.Key1 = key;
}
internal RelationshipWrapper(RelationshipWrapper wrapper, int ordinal, EntityKey key)
{
Debug.Assert(null != wrapper, "null RelationshipWrapper");
Debug.Assert((uint)ordinal <= 1u, "ordinal out of range");
Debug.Assert(null != (object)key, "null key2");
this.AssociationSet = wrapper.AssociationSet;
this.Key0 = (0 == ordinal) ? key : wrapper.Key0;
this.Key1 = (0 == ordinal) ? wrapper.Key1 : key;
}
internal RelationshipWrapper(AssociationSet extent,
KeyValuePair roleAndKey1,
KeyValuePair roleAndKey2)
: this(extent, roleAndKey1.Key, roleAndKey1.Value, roleAndKey2.Key, roleAndKey2.Value)
{
}
internal RelationshipWrapper(AssociationSet extent,
string role0, EntityKey key0,
string role1, EntityKey key1)
{
Debug.Assert(null != extent, "null AssociationSet");
Debug.Assert(null != (object)key0, "null key0");
Debug.Assert(null != (object)key1, "null key1");
AssociationSet = extent;
Debug.Assert(extent.ElementType.AssociationEndMembers.Count == 2, "only 2 ends are supported");
// this assert is explictly commented out to show that the two are similar but different
// we should always use AssociationEndMembers, never CorrespondingAssociationEndMember
//Debug.Assert(AssociationSet.AssociationSetEnds.Count == 2, "only 2 set ends supported");
//Debug.Assert(extent.ElementType.AssociationEndMembers[0] == AssociationSet.AssociationSetEnds[0].CorrespondingAssociationEndMember, "should be same end member");
//Debug.Assert(extent.ElementType.AssociationEndMembers[1] == AssociationSet.AssociationSetEnds[1].CorrespondingAssociationEndMember, "should be same end member");
if (extent.ElementType.AssociationEndMembers[0].Name == role0)
{
Debug.Assert(extent.ElementType.AssociationEndMembers[1].Name == role1, "a)roleAndKey1 Name differs");
Key0 = key0;
Key1 = key1;
}
else
{
Debug.Assert(extent.ElementType.AssociationEndMembers[0].Name == role1, "b)roleAndKey1 Name differs");
Debug.Assert(extent.ElementType.AssociationEndMembers[1].Name == role0, "b)roleAndKey0 Name differs");
Key0 = key1;
Key1 = key0;
}
}
internal ReadOnlyMetadataCollection AssociationEndMembers
{
get { return this.AssociationSet.ElementType.AssociationEndMembers; }
}
internal AssociationEndMember GetAssociationEndMember(EntityKey key)
{
Debug.Assert(Key0 == key || Key1 == key, "didn't match a key");
return AssociationEndMembers[(Key0 != key) ? 1 : 0];
}
internal EntityKey GetOtherEntityKey(EntityKey key)
{
return ((Key0 == key) ? Key1 : ((Key1 == key) ? Key0 : null));
}
internal EntityKey GetEntityKey(int ordinal)
{
switch (ordinal)
{
case 0:
return Key0;
case 1:
return Key1;
default:
throw EntityUtil.ArgumentOutOfRange("ordinal");
}
}
public override int GetHashCode()
{
return this.AssociationSet.Name.GetHashCode() ^ (this.Key0.GetHashCode() + this.Key1.GetHashCode());
}
public override bool Equals(object obj)
{
return Equals(obj as RelationshipWrapper);
}
public bool Equals(RelationshipWrapper wrapper)
{
return (Object.ReferenceEquals(this, wrapper) ||
((null != wrapper) &&
Object.ReferenceEquals(this.AssociationSet, wrapper.AssociationSet) &&
this.Key0.Equals(wrapper.Key0) &&
this.Key1.Equals(wrapper.Key1)));
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- CollectionChange.cs
- IImplicitResourceProvider.cs
- TranslateTransform.cs
- XmlSchemaExporter.cs
- BulletChrome.cs
- CallContext.cs
- XPathDocument.cs
- ThicknessKeyFrameCollection.cs
- AtomMaterializerLog.cs
- FlowDocument.cs
- WebPartsPersonalization.cs
- DataControlImageButton.cs
- _NegoState.cs
- AuthenticationModulesSection.cs
- CompilerTypeWithParams.cs
- ChooseAction.cs
- UnionExpr.cs
- FormsAuthenticationEventArgs.cs
- XPathNavigatorKeyComparer.cs
- HistoryEventArgs.cs
- AttributeSetAction.cs
- SqlLiftIndependentRowExpressions.cs
- ReadOnlyNameValueCollection.cs
- EnumCodeDomSerializer.cs
- Floater.cs
- XslAst.cs
- EntityDataSourceReferenceGroup.cs
- XmlSchemaComplexContent.cs
- AnimationClock.cs
- ServiceBuildProvider.cs
- RecipientServiceModelSecurityTokenRequirement.cs
- IndicFontClient.cs
- UdpChannelListener.cs
- BamlLocalizationDictionary.cs
- AppDomainManager.cs
- SwitchElementsCollection.cs
- safesecurityhelperavalon.cs
- CallbackTimeoutsElement.cs
- PersonalizationState.cs
- BinaryObjectReader.cs
- TableCellAutomationPeer.cs
- DbParameterHelper.cs
- Socket.cs
- DesignObjectWrapper.cs
- ChineseLunisolarCalendar.cs
- RemoteWebConfigurationHostServer.cs
- HttpListenerPrefixCollection.cs
- SecurityToken.cs
- Viewport2DVisual3D.cs
- HtmlImage.cs
- DelegateArgument.cs
- SafeNativeMethodsMilCoreApi.cs
- DigitShape.cs
- ConvertersCollection.cs
- JsonWriterDelegator.cs
- TransformerInfo.cs
- UpdateProgress.cs
- Latin1Encoding.cs
- XmlException.cs
- PriorityRange.cs
- MimeImporter.cs
- LocatorPartList.cs
- SocketException.cs
- ExpressionList.cs
- SafeRightsManagementHandle.cs
- ScrollContentPresenter.cs
- AnimationClock.cs
- ButtonFieldBase.cs
- HwndStylusInputProvider.cs
- PropertyInfoSet.cs
- Barrier.cs
- WebPartVerbCollection.cs
- ObjectConverter.cs
- initElementDictionary.cs
- TypeConverterAttribute.cs
- SqlDependencyUtils.cs
- ColorKeyFrameCollection.cs
- ExpressionLink.cs
- ViewLoader.cs
- LocatorPart.cs
- SignedXml.cs
- PlanCompiler.cs
- XsdDateTime.cs
- LoginCancelEventArgs.cs
- VisualStyleTypesAndProperties.cs
- FloaterParaClient.cs
- EnumValAlphaComparer.cs
- WindowsIdentity.cs
- SqlDependencyListener.cs
- GeneralTransform3D.cs
- EntitySqlQueryState.cs
- DbXmlEnabledProviderManifest.cs
- CodeMethodMap.cs
- PixelShader.cs
- TypeLoadException.cs
- IdentityReference.cs
- Vector3DValueSerializer.cs
- TraceHandler.cs
- FilePrompt.cs
- SelectingProviderEventArgs.cs