Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / ndp / fx / src / DataEntity / System / Data / Map / ViewGeneration / Validation / ViewKeyConstraint.cs / 2 / ViewKeyConstraint.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System.Collections.Generic; using System.Data.Mapping.ViewGeneration.Structures; using System.Data.Mapping.ViewGeneration.Utils; using System.Data.Common.Utils; using System.Text; using System.Data.Metadata.Edm; using System.Data.Entity; namespace System.Data.Mapping.ViewGeneration.Validation { // Class representing a key constraint on the view cell relations internal class ViewKeyConstraint : KeyConstraint{ #region Constructor // effects: Constructs a key constraint for the given relation and keyslots internal ViewKeyConstraint(ViewCellRelation relation, IEnumerable keySlots) : base(relation, keySlots, ViewCellSlot.SpecificEqualityComparer) { } #endregion #region Properties // effects: Returns the cell corresponding to this constraint internal Cell Cell { get { return CellRelation.Cell; } } #endregion #region Methods internal bool Implies(ViewKeyConstraint second) { if (false == Object.ReferenceEquals(CellRelation, second.CellRelation)) { return false; } // Check if the slots in this key are a subset of slots in // second. If it is a key in this e.g., then is certainly a key as well if (KeySlots.IsSubsetOf(second.KeySlots)) { return true; } // Now check for subsetting taking referential constraints into account // Check that each slot in KeySlots can be found in second.KeySlots if we take // slot equivalence into account Set secondKeySlots = new Set (second.KeySlots); foreach (ViewCellSlot firstSlot in KeySlots) { bool found = false; // Need to find a match for firstSlot foreach (ViewCellSlot secondSlot in secondKeySlots) { if (ProjectedSlot.EqualityComparer.Equals(firstSlot.SSlot, secondSlot.SSlot)) { // S-side is the same. Check if C-side is the same as well. If so, remove it // from secondKeySlots // We have to check for C-side equivalence in terms of actual equality // and equivalence via ref constraints. The former is needed since the // S-side key slots would typically be mapped to the same C-side slot. // The latter is needed since the same S-side key slot could be mapped // into two slots on the C-side that are connected via a ref constraint MemberPath path1 = firstSlot.CSlot.MemberPath; MemberPath path2 = secondSlot.CSlot.MemberPath; if (MemberPath.EqualityComparer.Equals(path1, path2) || path1.IsEquivalentViaRefConstraint(path2)) { secondKeySlots.Remove(secondSlot); found = true; break; } } } if (found == false) { return false; } } // The subsetting holds when referential constraints are taken into account return true; } // effects: Given the fact that rightKeyConstraint is not implied by a // leftSide key constraint, return a useful error message -- some S // was not implied by the C key constraints internal static ErrorLog.Record GetErrorRecord(ViewKeyConstraint rightKeyConstraint, MetadataWorkspace workspace) { List keySlots = new List (rightKeyConstraint.KeySlots); EntitySetBase table = keySlots[0].SSlot.MemberPath.Extent; EntitySetBase cSet = keySlots[0].CSlot.MemberPath.Extent; MemberPath tablePrefix = new MemberPath(table, workspace); MemberPath cSetPrefix = new MemberPath(cSet, workspace); ExtentKey tableKey = ExtentKey.GetPrimaryKeyForEntityType(tablePrefix, (EntityType) table.ElementType); ExtentKey cSetKey = null; if (cSet is EntitySet) { cSetKey = ExtentKey.GetPrimaryKeyForEntityType(cSetPrefix, (EntityType)cSet.ElementType); } else { cSetKey = ExtentKey.GetKeyForRelationType(cSetPrefix, (AssociationType)cSet.ElementType); } string message = Strings.ViewGen_KeyConstraint_Violation_5( table.Name, ViewCellSlot.SlotsToUserString(rightKeyConstraint.KeySlots, false /*isFromCside*/), tableKey.ToUserString(), cSet.Name, ViewCellSlot.SlotsToUserString(rightKeyConstraint.KeySlots, true /*isFromCside*/), cSetKey.ToUserString()); string debugMessage = StringUtil.FormatInvariant("PROBLEM: Not implied {0}", rightKeyConstraint); return new ErrorLog.Record(true, ViewGenErrorCode.KeyConstraintViolation, message, rightKeyConstraint.CellRelation.Cell, debugMessage); } // effects: Given the fact that none of the rightKeyConstraint are not implied by a // leftSide key constraint, return a useful error message (used for // the Update requirement internal static ErrorLog.Record GetErrorRecord(IEnumerable rightKeyConstraints, MetadataWorkspace workspace) { ViewKeyConstraint rightKeyConstraint = null; StringBuilder keyBuilder = new StringBuilder(); bool isFirst = true; foreach (ViewKeyConstraint rightConstraint in rightKeyConstraints) { string keyMsg = ViewCellSlot.SlotsToUserString(rightConstraint.KeySlots, true /*isFromCside*/); if (isFirst == false) { keyBuilder.Append("; "); } isFirst = false; keyBuilder.Append(keyMsg); rightKeyConstraint = rightConstraint; } List keySlots = new List (rightKeyConstraint.KeySlots); EntitySetBase table = keySlots[0].SSlot.MemberPath.Extent; EntitySetBase cSet = keySlots[0].CSlot.MemberPath.Extent; MemberPath tablePrefix = new MemberPath(table, workspace); ExtentKey tableKey = ExtentKey.GetPrimaryKeyForEntityType(tablePrefix, (EntityType) table.ElementType); string message; if (cSet is EntitySet) { message = System.Data.Entity.Strings.ViewGen_KeyConstraint_Update_Violation_EntitySet_3(keyBuilder.ToString(), cSet.Name, tableKey.ToUserString(), table.Name); } else { message = System.Data.Entity.Strings.ViewGen_KeyConstraint_Update_Violation_AssociationSet_2(cSet.Name, tableKey.ToUserString(), table.Name); } string debugMessage = StringUtil.FormatInvariant("PROBLEM: Not implied {0}", rightKeyConstraint); return new ErrorLog.Record(true, ViewGenErrorCode.KeyConstraintUpdateViolation, message, rightKeyConstraint.CellRelation.Cell, debugMessage); } #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System.Collections.Generic; using System.Data.Mapping.ViewGeneration.Structures; using System.Data.Mapping.ViewGeneration.Utils; using System.Data.Common.Utils; using System.Text; using System.Data.Metadata.Edm; using System.Data.Entity; namespace System.Data.Mapping.ViewGeneration.Validation { // Class representing a key constraint on the view cell relations internal class ViewKeyConstraint : KeyConstraint{ #region Constructor // effects: Constructs a key constraint for the given relation and keyslots internal ViewKeyConstraint(ViewCellRelation relation, IEnumerable keySlots) : base(relation, keySlots, ViewCellSlot.SpecificEqualityComparer) { } #endregion #region Properties // effects: Returns the cell corresponding to this constraint internal Cell Cell { get { return CellRelation.Cell; } } #endregion #region Methods internal bool Implies(ViewKeyConstraint second) { if (false == Object.ReferenceEquals(CellRelation, second.CellRelation)) { return false; } // Check if the slots in this key are a subset of slots in // second. If it is a key in this e.g., then is certainly a key as well if (KeySlots.IsSubsetOf(second.KeySlots)) { return true; } // Now check for subsetting taking referential constraints into account // Check that each slot in KeySlots can be found in second.KeySlots if we take // slot equivalence into account Set secondKeySlots = new Set (second.KeySlots); foreach (ViewCellSlot firstSlot in KeySlots) { bool found = false; // Need to find a match for firstSlot foreach (ViewCellSlot secondSlot in secondKeySlots) { if (ProjectedSlot.EqualityComparer.Equals(firstSlot.SSlot, secondSlot.SSlot)) { // S-side is the same. Check if C-side is the same as well. If so, remove it // from secondKeySlots // We have to check for C-side equivalence in terms of actual equality // and equivalence via ref constraints. The former is needed since the // S-side key slots would typically be mapped to the same C-side slot. // The latter is needed since the same S-side key slot could be mapped // into two slots on the C-side that are connected via a ref constraint MemberPath path1 = firstSlot.CSlot.MemberPath; MemberPath path2 = secondSlot.CSlot.MemberPath; if (MemberPath.EqualityComparer.Equals(path1, path2) || path1.IsEquivalentViaRefConstraint(path2)) { secondKeySlots.Remove(secondSlot); found = true; break; } } } if (found == false) { return false; } } // The subsetting holds when referential constraints are taken into account return true; } // effects: Given the fact that rightKeyConstraint is not implied by a // leftSide key constraint, return a useful error message -- some S // was not implied by the C key constraints internal static ErrorLog.Record GetErrorRecord(ViewKeyConstraint rightKeyConstraint, MetadataWorkspace workspace) { List keySlots = new List (rightKeyConstraint.KeySlots); EntitySetBase table = keySlots[0].SSlot.MemberPath.Extent; EntitySetBase cSet = keySlots[0].CSlot.MemberPath.Extent; MemberPath tablePrefix = new MemberPath(table, workspace); MemberPath cSetPrefix = new MemberPath(cSet, workspace); ExtentKey tableKey = ExtentKey.GetPrimaryKeyForEntityType(tablePrefix, (EntityType) table.ElementType); ExtentKey cSetKey = null; if (cSet is EntitySet) { cSetKey = ExtentKey.GetPrimaryKeyForEntityType(cSetPrefix, (EntityType)cSet.ElementType); } else { cSetKey = ExtentKey.GetKeyForRelationType(cSetPrefix, (AssociationType)cSet.ElementType); } string message = Strings.ViewGen_KeyConstraint_Violation_5( table.Name, ViewCellSlot.SlotsToUserString(rightKeyConstraint.KeySlots, false /*isFromCside*/), tableKey.ToUserString(), cSet.Name, ViewCellSlot.SlotsToUserString(rightKeyConstraint.KeySlots, true /*isFromCside*/), cSetKey.ToUserString()); string debugMessage = StringUtil.FormatInvariant("PROBLEM: Not implied {0}", rightKeyConstraint); return new ErrorLog.Record(true, ViewGenErrorCode.KeyConstraintViolation, message, rightKeyConstraint.CellRelation.Cell, debugMessage); } // effects: Given the fact that none of the rightKeyConstraint are not implied by a // leftSide key constraint, return a useful error message (used for // the Update requirement internal static ErrorLog.Record GetErrorRecord(IEnumerable rightKeyConstraints, MetadataWorkspace workspace) { ViewKeyConstraint rightKeyConstraint = null; StringBuilder keyBuilder = new StringBuilder(); bool isFirst = true; foreach (ViewKeyConstraint rightConstraint in rightKeyConstraints) { string keyMsg = ViewCellSlot.SlotsToUserString(rightConstraint.KeySlots, true /*isFromCside*/); if (isFirst == false) { keyBuilder.Append("; "); } isFirst = false; keyBuilder.Append(keyMsg); rightKeyConstraint = rightConstraint; } List keySlots = new List (rightKeyConstraint.KeySlots); EntitySetBase table = keySlots[0].SSlot.MemberPath.Extent; EntitySetBase cSet = keySlots[0].CSlot.MemberPath.Extent; MemberPath tablePrefix = new MemberPath(table, workspace); ExtentKey tableKey = ExtentKey.GetPrimaryKeyForEntityType(tablePrefix, (EntityType) table.ElementType); string message; if (cSet is EntitySet) { message = System.Data.Entity.Strings.ViewGen_KeyConstraint_Update_Violation_EntitySet_3(keyBuilder.ToString(), cSet.Name, tableKey.ToUserString(), table.Name); } else { message = System.Data.Entity.Strings.ViewGen_KeyConstraint_Update_Violation_AssociationSet_2(cSet.Name, tableKey.ToUserString(), table.Name); } string debugMessage = StringUtil.FormatInvariant("PROBLEM: Not implied {0}", rightKeyConstraint); return new ErrorLog.Record(true, ViewGenErrorCode.KeyConstraintUpdateViolation, message, rightKeyConstraint.CellRelation.Cell, debugMessage); } #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
- ValidatorCollection.cs
- smtppermission.cs
- CounterCreationDataCollection.cs
- ExpandCollapsePattern.cs
- NullReferenceException.cs
- AttributeData.cs
- ProcessHostMapPath.cs
- ValidationSummary.cs
- DbConnectionOptions.cs
- WebControlParameterProxy.cs
- SelectionRangeConverter.cs
- StandardBindingReliableSessionElement.cs
- DateTime.cs
- DataSourceListEditor.cs
- QueryOperationResponseOfT.cs
- CodeExporter.cs
- PasswordDeriveBytes.cs
- ItemType.cs
- ListItemCollection.cs
- StringFunctions.cs
- Schedule.cs
- CroppedBitmap.cs
- CodeMethodInvokeExpression.cs
- SafeHandles.cs
- ManipulationPivot.cs
- WebServiceTypeData.cs
- DesignerActionHeaderItem.cs
- ContentHostHelper.cs
- StoreItemCollection.cs
- MenuEventArgs.cs
- DbExpressionVisitor_TResultType.cs
- TextStore.cs
- DataSetMappper.cs
- ReverseQueryOperator.cs
- SafeLibraryHandle.cs
- PreviewPageInfo.cs
- ClusterRegistryConfigurationProvider.cs
- Delegate.cs
- QilExpression.cs
- PeerApplicationLaunchInfo.cs
- HostUtils.cs
- ObjectDisposedException.cs
- PointCollection.cs
- SerializableAttribute.cs
- ProcessHost.cs
- DataGridViewColumnTypePicker.cs
- PropertyInfoSet.cs
- CallSite.cs
- Rotation3D.cs
- MessageQueue.cs
- NominalTypeEliminator.cs
- EntityDataSourceUtil.cs
- Geometry.cs
- MemberRelationshipService.cs
- AtlasWeb.Designer.cs
- XmlAutoDetectWriter.cs
- CultureTableRecord.cs
- IssuedTokenParametersEndpointAddressElement.cs
- Token.cs
- TextEncodedRawTextWriter.cs
- RegexParser.cs
- DataStreams.cs
- SourceFilter.cs
- ConfigXmlAttribute.cs
- PipeException.cs
- TemplateBuilder.cs
- XsltLoader.cs
- Model3DCollection.cs
- SQLChars.cs
- BackgroundWorker.cs
- HttpsHostedTransportConfiguration.cs
- FormsAuthenticationTicket.cs
- SQLInt64Storage.cs
- StrongNamePublicKeyBlob.cs
- RuleConditionDialog.cs
- NetworkCredential.cs
- altserialization.cs
- RelOps.cs
- WebEvents.cs
- ProviderConnectionPoint.cs
- ProcessManager.cs
- ObjectStateFormatter.cs
- X509SecurityTokenProvider.cs
- DataPagerField.cs
- EncoderNLS.cs
- TreeNodeMouseHoverEvent.cs
- WindowsContainer.cs
- PartialCachingAttribute.cs
- Ref.cs
- DateRangeEvent.cs
- MsmqHostedTransportConfiguration.cs
- MsmqInputChannel.cs
- DataGridViewCellStyle.cs
- DependsOnAttribute.cs
- FormViewCommandEventArgs.cs
- ListView.cs
- PropertyMetadata.cs
- XmlMtomWriter.cs
- CompositeActivityDesigner.cs
- metadatamappinghashervisitor.cs