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 / AssociationSetMetadata.cs / 1 / AssociationSetMetadata.cs
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System.Data.Metadata.Edm;
using System.Data.Common.Utils;
using System.Data.Common.CommandTrees;
using System.Collections.Generic;
using System.Linq;
namespace System.Data.Mapping.Update.Internal
{
///
/// Encapsulates information about ends of an association set needed to correctly
/// interpret updates.
///
internal class AssociationSetMetadata
{
///
/// Gets association ends that must be modified if the association
/// is changed (e.g. the mapping of the association is conditioned
/// on some property of the end)
///
internal readonly Set RequiredEnds;
///
/// Gets association ends that may be implicitly modified as a result
/// of changes to the association (e.g. collocated entity with server
/// generated value)
///
internal readonly Set OptionalEnds;
///
/// Gets association ends whose values may influence the association
/// (e.g. where there is a ReferentialIntegrity or "common value" constraint)
///
internal readonly Set IncludedValueEnds;
///
/// true iff. there are interesting ends for this association set.
///
internal bool HasEnds
{
get { return 0 < RequiredEnds.Count || 0 < OptionalEnds.Count || 0 < IncludedValueEnds.Count; }
}
///
/// Initialize Metadata for an AssociationSet
///
internal AssociationSetMetadata(Set affectedTables, AssociationSet associationSet, MetadataWorkspace workspace)
{
// If there is only 1 table, there can be no ambiguity about the "destination" of a relationship, so such
// sets are not typically required.
bool isRequired = 1 < affectedTables.Count;
// determine the ends of the relationship
var ends = associationSet.AssociationSetEnds;
// find collocated entities
foreach (EntitySet table in affectedTables)
{
// Find extents influencing the table
DbQueryCommandTree updateMappingView = (DbQueryCommandTree)workspace.GetCqtView(table);
var influencingExtents = EntitySetRetriever.GetEntitySets(updateMappingView.Query);
foreach (EntitySet influencingExtent in influencingExtents)
{
foreach (var end in ends)
{
// If the extent is an end of the relationship and we haven't already added it to the
// required set...
if (end.EntitySet.EdmEquals(influencingExtent))
{
if (isRequired)
{
AddEnd(ref RequiredEnds, end.CorrespondingAssociationEndMember);
}
else if (null == RequiredEnds || !RequiredEnds.Contains(end.CorrespondingAssociationEndMember))
{
AddEnd(ref OptionalEnds, end.CorrespondingAssociationEndMember);
}
}
}
}
}
// fix Required and Optional sets
FixSet(ref RequiredEnds);
FixSet(ref OptionalEnds);
// for associations with referential constraints, the principal end is always interesting
// since its key values may take precedence over the key values of the dependent end
foreach (ReferentialConstraint constraint in associationSet.ElementType.ReferentialConstraints)
{
// FromRole is the principal end in the referential constraint
AssociationEndMember principalEnd = (AssociationEndMember)constraint.FromRole;
if (!RequiredEnds.Contains(principalEnd) &&
!OptionalEnds.Contains(principalEnd))
{
AddEnd(ref IncludedValueEnds, principalEnd);
}
}
FixSet(ref IncludedValueEnds);
}
///
/// Initialize given required ends.
///
internal AssociationSetMetadata(IEnumerable requiredEnds)
{
if (requiredEnds.Any())
{
RequiredEnds = new Set(requiredEnds);
}
FixSet(ref RequiredEnds);
FixSet(ref OptionalEnds);
FixSet(ref IncludedValueEnds);
}
static private void AddEnd(ref Set set, AssociationEndMember element)
{
if (null == set)
{
set = new Set();
}
set.Add(element);
}
static private void FixSet(ref Set set)
{
if (null == set)
{
set = Set.Empty;
}
else
{
set.MakeReadOnly();
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System.Data.Metadata.Edm;
using System.Data.Common.Utils;
using System.Data.Common.CommandTrees;
using System.Collections.Generic;
using System.Linq;
namespace System.Data.Mapping.Update.Internal
{
///
/// Encapsulates information about ends of an association set needed to correctly
/// interpret updates.
///
internal class AssociationSetMetadata
{
///
/// Gets association ends that must be modified if the association
/// is changed (e.g. the mapping of the association is conditioned
/// on some property of the end)
///
internal readonly Set RequiredEnds;
///
/// Gets association ends that may be implicitly modified as a result
/// of changes to the association (e.g. collocated entity with server
/// generated value)
///
internal readonly Set OptionalEnds;
///
/// Gets association ends whose values may influence the association
/// (e.g. where there is a ReferentialIntegrity or "common value" constraint)
///
internal readonly Set IncludedValueEnds;
///
/// true iff. there are interesting ends for this association set.
///
internal bool HasEnds
{
get { return 0 < RequiredEnds.Count || 0 < OptionalEnds.Count || 0 < IncludedValueEnds.Count; }
}
///
/// Initialize Metadata for an AssociationSet
///
internal AssociationSetMetadata(Set affectedTables, AssociationSet associationSet, MetadataWorkspace workspace)
{
// If there is only 1 table, there can be no ambiguity about the "destination" of a relationship, so such
// sets are not typically required.
bool isRequired = 1 < affectedTables.Count;
// determine the ends of the relationship
var ends = associationSet.AssociationSetEnds;
// find collocated entities
foreach (EntitySet table in affectedTables)
{
// Find extents influencing the table
DbQueryCommandTree updateMappingView = (DbQueryCommandTree)workspace.GetCqtView(table);
var influencingExtents = EntitySetRetriever.GetEntitySets(updateMappingView.Query);
foreach (EntitySet influencingExtent in influencingExtents)
{
foreach (var end in ends)
{
// If the extent is an end of the relationship and we haven't already added it to the
// required set...
if (end.EntitySet.EdmEquals(influencingExtent))
{
if (isRequired)
{
AddEnd(ref RequiredEnds, end.CorrespondingAssociationEndMember);
}
else if (null == RequiredEnds || !RequiredEnds.Contains(end.CorrespondingAssociationEndMember))
{
AddEnd(ref OptionalEnds, end.CorrespondingAssociationEndMember);
}
}
}
}
}
// fix Required and Optional sets
FixSet(ref RequiredEnds);
FixSet(ref OptionalEnds);
// for associations with referential constraints, the principal end is always interesting
// since its key values may take precedence over the key values of the dependent end
foreach (ReferentialConstraint constraint in associationSet.ElementType.ReferentialConstraints)
{
// FromRole is the principal end in the referential constraint
AssociationEndMember principalEnd = (AssociationEndMember)constraint.FromRole;
if (!RequiredEnds.Contains(principalEnd) &&
!OptionalEnds.Contains(principalEnd))
{
AddEnd(ref IncludedValueEnds, principalEnd);
}
}
FixSet(ref IncludedValueEnds);
}
///
/// Initialize given required ends.
///
internal AssociationSetMetadata(IEnumerable requiredEnds)
{
if (requiredEnds.Any())
{
RequiredEnds = new Set(requiredEnds);
}
FixSet(ref RequiredEnds);
FixSet(ref OptionalEnds);
FixSet(ref IncludedValueEnds);
}
static private void AddEnd(ref Set set, AssociationEndMember element)
{
if (null == set)
{
set = new Set();
}
set.Add(element);
}
static private void FixSet(ref Set set)
{
if (null == set)
{
set = Set.Empty;
}
else
{
set.MakeReadOnly();
}
}
}
}
// 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
- InputProviderSite.cs
- FixedHyperLink.cs
- SchemaElementDecl.cs
- TextContainerChangedEventArgs.cs
- WindowsHyperlink.cs
- Vector3DValueSerializer.cs
- HelloMessageApril2005.cs
- HitTestFilterBehavior.cs
- PersonalizationState.cs
- AuthorizationSection.cs
- UriScheme.cs
- DrawingAttributesDefaultValueFactory.cs
- TypeExtension.cs
- DataSourceControl.cs
- CodeDomSerializerException.cs
- TransformValueSerializer.cs
- KeyboardNavigation.cs
- NullableConverter.cs
- BufferedMessageWriter.cs
- HttpSessionStateBase.cs
- UIElementAutomationPeer.cs
- EventLogger.cs
- Shared.cs
- commandenforcer.cs
- CodeGotoStatement.cs
- TypographyProperties.cs
- DependencyStoreSurrogate.cs
- XmlSchemaAppInfo.cs
- ContentFilePart.cs
- ListComponentEditorPage.cs
- TreeNodeStyleCollection.cs
- DbDataSourceEnumerator.cs
- DBBindings.cs
- WindowsListViewItemCheckBox.cs
- sortedlist.cs
- ImageFormat.cs
- IssuanceLicense.cs
- OraclePermission.cs
- ApplicationSecurityManager.cs
- CodeNamespaceImportCollection.cs
- XPathBinder.cs
- NamedPermissionSet.cs
- PolyBezierSegment.cs
- DocumentPaginator.cs
- loginstatus.cs
- DataControlFieldHeaderCell.cs
- LocalValueEnumerator.cs
- ActionFrame.cs
- DataKey.cs
- ValidatorCollection.cs
- ScriptManager.cs
- CachedTypeface.cs
- CapabilitiesUse.cs
- DurationConverter.cs
- InputProcessorProfilesLoader.cs
- XpsFont.cs
- WebPartCloseVerb.cs
- Documentation.cs
- FacetValues.cs
- CaseStatement.cs
- TextBoxAutoCompleteSourceConverter.cs
- SingleQueryOperator.cs
- PlaceHolder.cs
- SecondaryViewProvider.cs
- TimeSpanConverter.cs
- ByteAnimationUsingKeyFrames.cs
- DynamicDataExtensions.cs
- Completion.cs
- DeclarativeExpressionConditionDeclaration.cs
- PseudoWebRequest.cs
- ChannelFactoryRefCache.cs
- TabControlToolboxItem.cs
- DeferredBinaryDeserializerExtension.cs
- ManagementOptions.cs
- XsltConvert.cs
- DesignerVerbCollection.cs
- ExceptionValidationRule.cs
- SystemResourceHost.cs
- Size3D.cs
- DataColumnCollection.cs
- LiteralTextContainerControlBuilder.cs
- VariableQuery.cs
- pingexception.cs
- FreezableCollection.cs
- TraversalRequest.cs
- MdiWindowListItemConverter.cs
- DropDownButton.cs
- EntityDataReader.cs
- StateWorkerRequest.cs
- BrushValueSerializer.cs
- SqlNamer.cs
- FormsAuthentication.cs
- SchemaMapping.cs
- TransactionScope.cs
- MdImport.cs
- HtmlContainerControl.cs
- SmiConnection.cs
- DataGridViewImageCell.cs
- ErrorWebPart.cs
- MarginCollapsingState.cs