Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / ndp / fx / src / DataEntity / System / Data / Map / Update / Internal / CompositeKey.cs / 2 / CompositeKey.cs
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using KeyComponent = System.Collections.Generic.KeyValuePair;
using System.Data.Common.Utils;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
namespace System.Data.Mapping.Update.Internal
{
///
/// Represents a key composed of multiple parts.
///
internal class CompositeKey
{
#region Fields
///
/// Gets components of this composite key.
///
internal readonly KeyComponent[] KeyComponents;
#endregion
#region Constructors
///
/// Initialize a new composite key using the given constant values. Order is important.
///
/// Constants composing key
internal CompositeKey(PropagatorResult[] constants)
{
Debug.Assert(null != constants, "key values must be given");
KeyComponents = new KeyComponent[constants.Length];
for (int i = 0; i < constants.Length; i++)
{
PropagatorResult constant = constants[i];
Debug.Assert(null != constant, "all key values must be set");
Int64 identifier = constant.Identifier;
KeyComponents[i] = new KeyComponent(constant, identifier);
}
}
#endregion
#region Methods
///
/// Creates a key comparer operating in the context of the given translator.
///
internal static IEqualityComparer CreateComparer(KeyManager keyManager)
{
return new CompositeKeyComparer(keyManager);
}
#endregion
///
/// Equality and comparison implementation for composite keys.
///
private class CompositeKeyComparer : IEqualityComparer
{
private readonly KeyManager _manager;
internal CompositeKeyComparer(KeyManager manager)
{
_manager = EntityUtil.CheckArgumentNull(manager, "manager");
}
// determines equality by comparing each key component
public bool Equals(CompositeKey left, CompositeKey right)
{
// Short circuit the comparison if we know the other reference is equivalent
if (object.ReferenceEquals(left, right)) { return true; }
// If either side is null, return false order (both can't be null because of
// the previous check)
if (null == left || null == right) { return false; }
Debug.Assert(null != left.KeyComponents && null != right.KeyComponents,
"(Update/JoinPropagator) CompositeKey must be initialized");
if (left.KeyComponents.Length != right.KeyComponents.Length) { return false; }
for (int i = 0; i < left.KeyComponents.Length; i++)
{
object leftValue = GetValue(left.KeyComponents[i]);
object rightValue = GetValue(right.KeyComponents[i]);
if (!CdpEqualityComparer.DefaultEqualityComparer.Equals(leftValue, rightValue))
{
return false;
}
}
return true;
}
// creates a hash code by XORing hash codes for all key components.
public int GetHashCode(CompositeKey key)
{
EntityUtil.CheckArgumentNull(key, "key");
int result = 0;
foreach (KeyComponent keyComponent in key.KeyComponents)
{
result ^= GetValue(keyComponent).GetHashCode();
}
return result;
}
// Gets the value to use for equality checks given a key component
private object GetValue(KeyComponent keyComponent)
{
if (keyComponent.Value == PropagatorResult.NullIdentifier)
{
// no identifier exists for this key component, so use the actual key
// value
Debug.Assert(null != keyComponent.Key && null != keyComponent.Key,
"key value must not be null");
return keyComponent.Key.GetSimpleValue();
}
else
{
// use the identifier rather than the actual value (since uniqueness
// is not guaranteed for client generated key values in the object layer)
return _manager.GetCanonicalIdentifier(keyComponent.Value);
}
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using KeyComponent = System.Collections.Generic.KeyValuePair;
using System.Data.Common.Utils;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
namespace System.Data.Mapping.Update.Internal
{
///
/// Represents a key composed of multiple parts.
///
internal class CompositeKey
{
#region Fields
///
/// Gets components of this composite key.
///
internal readonly KeyComponent[] KeyComponents;
#endregion
#region Constructors
///
/// Initialize a new composite key using the given constant values. Order is important.
///
/// Constants composing key
internal CompositeKey(PropagatorResult[] constants)
{
Debug.Assert(null != constants, "key values must be given");
KeyComponents = new KeyComponent[constants.Length];
for (int i = 0; i < constants.Length; i++)
{
PropagatorResult constant = constants[i];
Debug.Assert(null != constant, "all key values must be set");
Int64 identifier = constant.Identifier;
KeyComponents[i] = new KeyComponent(constant, identifier);
}
}
#endregion
#region Methods
///
/// Creates a key comparer operating in the context of the given translator.
///
internal static IEqualityComparer CreateComparer(KeyManager keyManager)
{
return new CompositeKeyComparer(keyManager);
}
#endregion
///
/// Equality and comparison implementation for composite keys.
///
private class CompositeKeyComparer : IEqualityComparer
{
private readonly KeyManager _manager;
internal CompositeKeyComparer(KeyManager manager)
{
_manager = EntityUtil.CheckArgumentNull(manager, "manager");
}
// determines equality by comparing each key component
public bool Equals(CompositeKey left, CompositeKey right)
{
// Short circuit the comparison if we know the other reference is equivalent
if (object.ReferenceEquals(left, right)) { return true; }
// If either side is null, return false order (both can't be null because of
// the previous check)
if (null == left || null == right) { return false; }
Debug.Assert(null != left.KeyComponents && null != right.KeyComponents,
"(Update/JoinPropagator) CompositeKey must be initialized");
if (left.KeyComponents.Length != right.KeyComponents.Length) { return false; }
for (int i = 0; i < left.KeyComponents.Length; i++)
{
object leftValue = GetValue(left.KeyComponents[i]);
object rightValue = GetValue(right.KeyComponents[i]);
if (!CdpEqualityComparer.DefaultEqualityComparer.Equals(leftValue, rightValue))
{
return false;
}
}
return true;
}
// creates a hash code by XORing hash codes for all key components.
public int GetHashCode(CompositeKey key)
{
EntityUtil.CheckArgumentNull(key, "key");
int result = 0;
foreach (KeyComponent keyComponent in key.KeyComponents)
{
result ^= GetValue(keyComponent).GetHashCode();
}
return result;
}
// Gets the value to use for equality checks given a key component
private object GetValue(KeyComponent keyComponent)
{
if (keyComponent.Value == PropagatorResult.NullIdentifier)
{
// no identifier exists for this key component, so use the actual key
// value
Debug.Assert(null != keyComponent.Key && null != keyComponent.Key,
"key value must not be null");
return keyComponent.Key.GetSimpleValue();
}
else
{
// use the identifier rather than the actual value (since uniqueness
// is not guaranteed for client generated key values in the object layer)
return _manager.GetCanonicalIdentifier(keyComponent.Value);
}
}
}
}
}
// 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
- ProviderCommandInfoUtils.cs
- SettingsPropertyCollection.cs
- InteropAutomationProvider.cs
- DocumentPageView.cs
- StandardTransformFactory.cs
- ScrollEventArgs.cs
- CharEnumerator.cs
- MetadataArtifactLoaderResource.cs
- Span.cs
- MetadataPropertyAttribute.cs
- ThreadAttributes.cs
- ObjectSpanRewriter.cs
- SqlClientFactory.cs
- MetadataCollection.cs
- EventLogLink.cs
- ToolStripItem.cs
- BrowserDefinitionCollection.cs
- EntityTransaction.cs
- Panel.cs
- TrackPoint.cs
- DateRangeEvent.cs
- CodeSnippetExpression.cs
- XamlSerializer.cs
- SafeProcessHandle.cs
- LogAppendAsyncResult.cs
- SeparatorAutomationPeer.cs
- ELinqQueryState.cs
- DbReferenceCollection.cs
- ThrowHelper.cs
- ToolboxComponentsCreatedEventArgs.cs
- securitycriticaldataformultiplegetandset.cs
- objectquery_tresulttype.cs
- MimeMultiPart.cs
- TableLayoutStyle.cs
- TextSelectionHelper.cs
- PipelineModuleStepContainer.cs
- Symbol.cs
- Validator.cs
- WorkflowIdleBehavior.cs
- WebHeaderCollection.cs
- DataGridViewHeaderCell.cs
- RoleGroupCollection.cs
- DodSequenceMerge.cs
- HtmlTextViewAdapter.cs
- Bidi.cs
- BaseDataList.cs
- CodeIterationStatement.cs
- EntityDataSourceReferenceGroup.cs
- DynamicExpression.cs
- ScriptingSectionGroup.cs
- PriorityBindingExpression.cs
- EventManager.cs
- PackageRelationshipSelector.cs
- KeyedCollection.cs
- AuthStoreRoleProvider.cs
- ReferencedType.cs
- SequentialWorkflowRootDesigner.cs
- WaitHandleCannotBeOpenedException.cs
- ReturnType.cs
- CheckBoxStandardAdapter.cs
- SqlXml.cs
- PaintEvent.cs
- ScalarConstant.cs
- CheckBoxBaseAdapter.cs
- SemaphoreFullException.cs
- SqlNodeTypeOperators.cs
- RichTextBox.cs
- HtmlTableRowCollection.cs
- CopyOfAction.cs
- Condition.cs
- DigitalSignatureProvider.cs
- shaperfactory.cs
- CodeAccessPermission.cs
- ExpressionBuilder.cs
- AuthenticodeSignatureInformation.cs
- AbandonedMutexException.cs
- PageClientProxyGenerator.cs
- coordinatorscratchpad.cs
- CompositeActivityTypeDescriptor.cs
- X509Extension.cs
- ProcessInfo.cs
- TargetParameterCountException.cs
- ProfileProvider.cs
- FacetValues.cs
- WebDescriptionAttribute.cs
- ClockController.cs
- TextParagraphCache.cs
- SizeAnimation.cs
- BaseValidator.cs
- Parameter.cs
- FixUpCollection.cs
- ExpressionBinding.cs
- PictureBox.cs
- XmlExpressionDumper.cs
- DivideByZeroException.cs
- MediaPlayerState.cs
- CLRBindingWorker.cs
- DataGridViewToolTip.cs
- LinqDataSourceValidationException.cs
- ConfigurationProperty.cs