Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / ndp / fx / src / DataEntity / System / Data / Query / InternalTrees / relpropertyhelper.cs / 2 / relpropertyhelper.cs
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....], [....]
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Diagnostics;
using System.Data.Common;
using System.Data.Metadata.Edm;
namespace System.Data.Query.InternalTrees
{
///
/// A "Rel" property is best thought of as a collocated reference (aka foreign key).
/// Any entity may have zero or more rel-properties carried along with it (purely
/// as a means to optimize for common relationship traversal scenarios)
///
/// Although the definition is lax here, we only deal with RelProperties that
/// are one-ended (ie) the target multiplicity is at most One.
///
/// Consider for example, an Order entity with a (N:1) Order-Customer relationship. The Customer ref
/// will be treated as a rel property for the Order entity.
/// Similarly, the OrderLine entity may have an Order ref rel property (assuming that there was
/// a N:1 relationship between OrderLine and Order)
///
internal sealed class RelProperty
{
#region private state
private readonly RelationshipType m_relationshipType;
private readonly RelationshipEndMember m_fromEnd;
private readonly RelationshipEndMember m_toEnd;
#endregion
#region constructors
internal RelProperty(RelationshipType relationshipType, RelationshipEndMember fromEnd, RelationshipEndMember toEnd)
{
m_relationshipType = relationshipType;
m_fromEnd = fromEnd;
m_toEnd = toEnd;
}
#endregion
#region public APIs
///
/// The relationship
///
public RelationshipType Relationship { get { return m_relationshipType; } }
///
/// The source end of the relationship
///
public RelationshipEndMember FromEnd { get { return m_fromEnd; } }
///
/// the target end of the relationship
///
public RelationshipEndMember ToEnd { get { return m_toEnd; } }
///
/// Our definition of equality
///
///
///
public override bool Equals(object obj)
{
RelProperty other = obj as RelProperty;
return (other != null &&
this.Relationship.EdmEquals(other.Relationship) &&
this.FromEnd.EdmEquals(other.FromEnd) &&
this.ToEnd.EdmEquals(other.ToEnd));
}
///
/// our hash code
///
///
public override int GetHashCode()
{
return this.ToEnd.Identity.GetHashCode();
}
///
/// String form
///
///
[DebuggerNonUserCode]
public override string ToString()
{
return m_relationshipType.ToString() + ":" +
m_fromEnd.ToString() + ":" +
m_toEnd.ToString();
}
#endregion
}
///
/// A helper class for all rel-properties
///
internal sealed class RelPropertyHelper
{
#region private state
private Dictionary> _relPropertyMap;
private HashSet _interestingRelProperties;
#endregion
#region private methods
///
/// Add the rel property induced by the specified relationship, (if the target
/// end has a multiplicity of one)
/// We only keep track of rel-properties that are "interesting"
///
/// the association relationship
/// source end of the relationship traversal
/// target end of the traversal
private void AddRelProperty(AssociationType associationType,
AssociationEndMember fromEnd, AssociationEndMember toEnd)
{
if (toEnd.RelationshipMultiplicity == RelationshipMultiplicity.Many)
{
return;
}
RelProperty prop = new RelProperty(associationType, fromEnd, toEnd);
if (_interestingRelProperties == null ||
!_interestingRelProperties.Contains(prop))
{
return;
}
EntityTypeBase entityType = (EntityTypeBase)((RefType)fromEnd.TypeUsage.EdmType).ElementType;
List propList;
if (!_relPropertyMap.TryGetValue(entityType, out propList))
{
propList = new List();
_relPropertyMap[entityType] = propList;
}
propList.Add(prop);
}
///
/// Add any rel properties that are induced by the supplied relationship
///
/// the relationship
private void ProcessRelationship(RelationshipType relationshipType)
{
AssociationType associationType = relationshipType as AssociationType;
if (associationType == null)
{
return;
}
// Handle only binary associations
if (associationType.AssociationEndMembers.Count != 2)
{
return;
}
AssociationEndMember end0 = associationType.AssociationEndMembers[0];
AssociationEndMember end1 = associationType.AssociationEndMembers[1];
AddRelProperty(associationType, end0, end1);
AddRelProperty(associationType, end1, end0);
}
#endregion
#region constructors
internal RelPropertyHelper(MetadataWorkspace ws, HashSet interestingRelProperties)
{
_relPropertyMap = new Dictionary>();
_interestingRelProperties = interestingRelProperties;
foreach (RelationshipType relationshipType in ws.GetItems(DataSpace.CSpace))
{
ProcessRelationship(relationshipType);
}
}
#endregion
#region public APIs
///
/// Get the rel properties declared by this type (and *not* by any of its subtypes)
///
/// the entity type
/// set of rel properties declared for this type
internal IEnumerable GetDeclaredOnlyRelProperties(EntityTypeBase entityType)
{
List relProperties;
if (_relPropertyMap.TryGetValue(entityType, out relProperties))
{
foreach (RelProperty p in relProperties)
{
yield return p;
}
}
yield break;
}
///
/// Get the rel-properties of this entity and its supertypes (starting from the root)
///
/// the entity type
/// set of rel-properties for this entity type (and its supertypes)
internal IEnumerable GetRelProperties(EntityTypeBase entityType)
{
if (entityType.BaseType != null)
{
foreach (RelProperty p in GetRelProperties(entityType.BaseType as EntityTypeBase))
{
yield return p;
}
}
foreach (RelProperty p in GetDeclaredOnlyRelProperties(entityType))
{
yield return p;
}
}
#endregion
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....], [....]
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Diagnostics;
using System.Data.Common;
using System.Data.Metadata.Edm;
namespace System.Data.Query.InternalTrees
{
///
/// A "Rel" property is best thought of as a collocated reference (aka foreign key).
/// Any entity may have zero or more rel-properties carried along with it (purely
/// as a means to optimize for common relationship traversal scenarios)
///
/// Although the definition is lax here, we only deal with RelProperties that
/// are one-ended (ie) the target multiplicity is at most One.
///
/// Consider for example, an Order entity with a (N:1) Order-Customer relationship. The Customer ref
/// will be treated as a rel property for the Order entity.
/// Similarly, the OrderLine entity may have an Order ref rel property (assuming that there was
/// a N:1 relationship between OrderLine and Order)
///
internal sealed class RelProperty
{
#region private state
private readonly RelationshipType m_relationshipType;
private readonly RelationshipEndMember m_fromEnd;
private readonly RelationshipEndMember m_toEnd;
#endregion
#region constructors
internal RelProperty(RelationshipType relationshipType, RelationshipEndMember fromEnd, RelationshipEndMember toEnd)
{
m_relationshipType = relationshipType;
m_fromEnd = fromEnd;
m_toEnd = toEnd;
}
#endregion
#region public APIs
///
/// The relationship
///
public RelationshipType Relationship { get { return m_relationshipType; } }
///
/// The source end of the relationship
///
public RelationshipEndMember FromEnd { get { return m_fromEnd; } }
///
/// the target end of the relationship
///
public RelationshipEndMember ToEnd { get { return m_toEnd; } }
///
/// Our definition of equality
///
///
///
public override bool Equals(object obj)
{
RelProperty other = obj as RelProperty;
return (other != null &&
this.Relationship.EdmEquals(other.Relationship) &&
this.FromEnd.EdmEquals(other.FromEnd) &&
this.ToEnd.EdmEquals(other.ToEnd));
}
///
/// our hash code
///
///
public override int GetHashCode()
{
return this.ToEnd.Identity.GetHashCode();
}
///
/// String form
///
///
[DebuggerNonUserCode]
public override string ToString()
{
return m_relationshipType.ToString() + ":" +
m_fromEnd.ToString() + ":" +
m_toEnd.ToString();
}
#endregion
}
///
/// A helper class for all rel-properties
///
internal sealed class RelPropertyHelper
{
#region private state
private Dictionary> _relPropertyMap;
private HashSet _interestingRelProperties;
#endregion
#region private methods
///
/// Add the rel property induced by the specified relationship, (if the target
/// end has a multiplicity of one)
/// We only keep track of rel-properties that are "interesting"
///
/// the association relationship
/// source end of the relationship traversal
/// target end of the traversal
private void AddRelProperty(AssociationType associationType,
AssociationEndMember fromEnd, AssociationEndMember toEnd)
{
if (toEnd.RelationshipMultiplicity == RelationshipMultiplicity.Many)
{
return;
}
RelProperty prop = new RelProperty(associationType, fromEnd, toEnd);
if (_interestingRelProperties == null ||
!_interestingRelProperties.Contains(prop))
{
return;
}
EntityTypeBase entityType = (EntityTypeBase)((RefType)fromEnd.TypeUsage.EdmType).ElementType;
List propList;
if (!_relPropertyMap.TryGetValue(entityType, out propList))
{
propList = new List();
_relPropertyMap[entityType] = propList;
}
propList.Add(prop);
}
///
/// Add any rel properties that are induced by the supplied relationship
///
/// the relationship
private void ProcessRelationship(RelationshipType relationshipType)
{
AssociationType associationType = relationshipType as AssociationType;
if (associationType == null)
{
return;
}
// Handle only binary associations
if (associationType.AssociationEndMembers.Count != 2)
{
return;
}
AssociationEndMember end0 = associationType.AssociationEndMembers[0];
AssociationEndMember end1 = associationType.AssociationEndMembers[1];
AddRelProperty(associationType, end0, end1);
AddRelProperty(associationType, end1, end0);
}
#endregion
#region constructors
internal RelPropertyHelper(MetadataWorkspace ws, HashSet interestingRelProperties)
{
_relPropertyMap = new Dictionary>();
_interestingRelProperties = interestingRelProperties;
foreach (RelationshipType relationshipType in ws.GetItems(DataSpace.CSpace))
{
ProcessRelationship(relationshipType);
}
}
#endregion
#region public APIs
///
/// Get the rel properties declared by this type (and *not* by any of its subtypes)
///
/// the entity type
/// set of rel properties declared for this type
internal IEnumerable GetDeclaredOnlyRelProperties(EntityTypeBase entityType)
{
List relProperties;
if (_relPropertyMap.TryGetValue(entityType, out relProperties))
{
foreach (RelProperty p in relProperties)
{
yield return p;
}
}
yield break;
}
///
/// Get the rel-properties of this entity and its supertypes (starting from the root)
///
/// the entity type
/// set of rel-properties for this entity type (and its supertypes)
internal IEnumerable GetRelProperties(EntityTypeBase entityType)
{
if (entityType.BaseType != null)
{
foreach (RelProperty p in GetRelProperties(entityType.BaseType as EntityTypeBase))
{
yield return p;
}
}
foreach (RelProperty p in GetDeclaredOnlyRelProperties(entityType))
{
yield return p;
}
}
#endregion
}
}
// 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
- GenericRootAutomationPeer.cs
- ISO2022Encoding.cs
- HashLookup.cs
- QilGeneratorEnv.cs
- HttpProfileBase.cs
- RangeValidator.cs
- PlaceHolder.cs
- ErrorTableItemStyle.cs
- ProbeDuplexCD1AsyncResult.cs
- ImagingCache.cs
- SvcMapFileSerializer.cs
- KeyTimeConverter.cs
- UnsafeNativeMethods.cs
- GroupLabel.cs
- DockPanel.cs
- NonBatchDirectoryCompiler.cs
- QilScopedVisitor.cs
- Visual3DCollection.cs
- Size3D.cs
- PassportAuthenticationModule.cs
- Boolean.cs
- URLString.cs
- RotateTransform.cs
- DesignerAutoFormat.cs
- CompModHelpers.cs
- StringKeyFrameCollection.cs
- FormViewDeletedEventArgs.cs
- ConnectorRouter.cs
- ParentUndoUnit.cs
- DSASignatureDeformatter.cs
- ProtectedConfigurationSection.cs
- SwitchLevelAttribute.cs
- IndicCharClassifier.cs
- ProxyFragment.cs
- DataTablePropertyDescriptor.cs
- TrustLevelCollection.cs
- SizeFConverter.cs
- SystemIcmpV6Statistics.cs
- MDIWindowDialog.cs
- Comparer.cs
- KeyedCollection.cs
- WebPartConnectionsEventArgs.cs
- HashMembershipCondition.cs
- InfoCardRSAPKCS1SignatureFormatter.cs
- ExpressionConverter.cs
- DataGridViewRowHeaderCell.cs
- Int32RectValueSerializer.cs
- Native.cs
- CheckBox.cs
- BuildProviderUtils.cs
- PenLineJoinValidation.cs
- MediaCommands.cs
- LogicalExpr.cs
- DataGridDefaultColumnWidthTypeConverter.cs
- SoapExtensionStream.cs
- DataReaderContainer.cs
- PeerPresenceInfo.cs
- MimeParameterWriter.cs
- Pointer.cs
- ColumnPropertiesGroup.cs
- ResourceCollectionInfo.cs
- DataRelation.cs
- ListView.cs
- DataGridPagerStyle.cs
- ActivityBuilderHelper.cs
- LayoutEvent.cs
- ExpressionBuilder.cs
- Container.cs
- LoadedOrUnloadedOperation.cs
- UniformGrid.cs
- ObjectRef.cs
- RichTextBoxContextMenu.cs
- CapabilitiesAssignment.cs
- TaskFileService.cs
- MarkupProperty.cs
- ExecutionEngineException.cs
- CellConstant.cs
- CharAnimationBase.cs
- XmlNamespaceDeclarationsAttribute.cs
- ConfigXmlComment.cs
- XmlObjectSerializer.cs
- FormViewUpdatedEventArgs.cs
- WebBrowserBase.cs
- SimpleTypeResolver.cs
- WpfXamlMember.cs
- NameTable.cs
- PassportPrincipal.cs
- ImmutableObjectAttribute.cs
- FastPropertyAccessor.cs
- ExceptionUtil.cs
- BamlReader.cs
- GenericsInstances.cs
- TreeIterator.cs
- SectionXmlInfo.cs
- ListView.cs
- SqlWriter.cs
- AVElementHelper.cs
- HMAC.cs
- ConnectionsZoneAutoFormat.cs
- LocationChangedEventArgs.cs