Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntity / System / Data / EntityModel / SchemaObjectModel / Relationship.cs / 1305376 / Relationship.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System; using System.Data.Objects.DataClasses; using System.Collections.Generic; using System.Diagnostics; using System.Xml; using System.Data; using System.Data.Metadata.Edm; namespace System.Data.EntityModel.SchemaObjectModel { ////// Represents an Association element /// internal sealed class Relationship : SchemaType, IRelationship { private RelationshipKind _relationshipKind; private RelationshipEndCollection _ends; private List_constraints; private bool _isForeignKey; /// /// Construct a Relationship object /// /// the parent /// the kind of relationship public Relationship(Schema parent, RelationshipKind kind) : base(parent) { RelationshipKind = kind; if (Schema.DataModel == SchemaDataModelOption.EntityDataModel) { _isForeignKey = false; OtherContent.Add(Schema.SchemaSource); } else if (Schema.DataModel == SchemaDataModelOption.ProviderDataModel) { _isForeignKey = true; } } ////// List of Ends defined for this Association /// public IListEnds { get { if ( _ends == null ) _ends = new RelationshipEndCollection(); return _ends; } } /// /// Returns the list of constraints on this relation /// public IListConstraints { get { if (_constraints == null) { _constraints = new List (); } return _constraints; } } public bool TryGetEnd( string roleName, out IRelationshipEnd end ) { return _ends.TryGetEnd( roleName, out end ); } /// /// Is this an Association /// public RelationshipKind RelationshipKind { get { return _relationshipKind; } private set { _relationshipKind = value; } } ////// Is this a foreign key (aka foreign key) relationship? /// public bool IsForeignKey { get { return _isForeignKey; } } ////// do whole element validation /// ///internal override void Validate() { base.Validate(); bool foundOperations = false; foreach ( RelationshipEnd end in Ends ) { end.Validate(); if ( RelationshipKind == RelationshipKind.Association ) { if ( end.Operations.Count > 0 ) { if ( foundOperations ) end.AddError( ErrorCode.InvalidOperation, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.InvalidOperationMultipleEndsInAssociation); foundOperations = true; } } } if (Constraints.Count == 0) { if (this.Schema.DataModel == SchemaDataModelOption.ProviderDataModel) { AddError(ErrorCode.MissingConstraintOnRelationshipType, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.MissingConstraintOnRelationshipType(FQName)); } } else { foreach (ReferentialConstraint constraint in Constraints) { constraint.Validate(); } } } /// /// do whole element resolution /// internal override void ResolveTopLevelNames() { base.ResolveTopLevelNames(); foreach ( RelationshipEnd end in Ends ) end.ResolveTopLevelNames(); foreach (ReferentialConstraint referentialConstraint in Constraints) { referentialConstraint.ResolveTopLevelNames(); } } protected override bool HandleElement(XmlReader reader) { if (base.HandleElement(reader)) { return true; } else if (CanHandleElement(reader, XmlConstants.End)) { HandleEndElement(reader); return true; } else if (CanHandleElement(reader, XmlConstants.ReferentialConstraint)) { HandleConstraintElement(reader); return true; } return false; } ////// handle the End child element /// /// XmlReader positioned at the end element private void HandleEndElement(XmlReader reader) { Debug.Assert(reader != null); RelationshipEnd end = new RelationshipEnd(this); end.Parse(reader); if (Ends.Count == 2) { AddError( ErrorCode.InvalidAssociation, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.TooManyAssociationEnds(FQName ) ); return; } Ends.Add(end); } ////// handle the constraint element /// /// XmlReader positioned at the constraint element private void HandleConstraintElement(XmlReader reader) { Debug.Assert(reader != null); ReferentialConstraint constraint = new ReferentialConstraint(this); constraint.Parse(reader); this.Constraints.Add(constraint); if (this.Schema.DataModel == SchemaDataModelOption.EntityDataModel && this.Schema.SchemaVersion >= XmlConstants.EdmVersionForV2) { // in V2, referential constraint implies foreign key _isForeignKey = true; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System; using System.Data.Objects.DataClasses; using System.Collections.Generic; using System.Diagnostics; using System.Xml; using System.Data; using System.Data.Metadata.Edm; namespace System.Data.EntityModel.SchemaObjectModel { ////// Represents an Association element /// internal sealed class Relationship : SchemaType, IRelationship { private RelationshipKind _relationshipKind; private RelationshipEndCollection _ends; private List_constraints; private bool _isForeignKey; /// /// Construct a Relationship object /// /// the parent /// the kind of relationship public Relationship(Schema parent, RelationshipKind kind) : base(parent) { RelationshipKind = kind; if (Schema.DataModel == SchemaDataModelOption.EntityDataModel) { _isForeignKey = false; OtherContent.Add(Schema.SchemaSource); } else if (Schema.DataModel == SchemaDataModelOption.ProviderDataModel) { _isForeignKey = true; } } ////// List of Ends defined for this Association /// public IListEnds { get { if ( _ends == null ) _ends = new RelationshipEndCollection(); return _ends; } } /// /// Returns the list of constraints on this relation /// public IListConstraints { get { if (_constraints == null) { _constraints = new List (); } return _constraints; } } public bool TryGetEnd( string roleName, out IRelationshipEnd end ) { return _ends.TryGetEnd( roleName, out end ); } /// /// Is this an Association /// public RelationshipKind RelationshipKind { get { return _relationshipKind; } private set { _relationshipKind = value; } } ////// Is this a foreign key (aka foreign key) relationship? /// public bool IsForeignKey { get { return _isForeignKey; } } ////// do whole element validation /// ///internal override void Validate() { base.Validate(); bool foundOperations = false; foreach ( RelationshipEnd end in Ends ) { end.Validate(); if ( RelationshipKind == RelationshipKind.Association ) { if ( end.Operations.Count > 0 ) { if ( foundOperations ) end.AddError( ErrorCode.InvalidOperation, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.InvalidOperationMultipleEndsInAssociation); foundOperations = true; } } } if (Constraints.Count == 0) { if (this.Schema.DataModel == SchemaDataModelOption.ProviderDataModel) { AddError(ErrorCode.MissingConstraintOnRelationshipType, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.MissingConstraintOnRelationshipType(FQName)); } } else { foreach (ReferentialConstraint constraint in Constraints) { constraint.Validate(); } } } /// /// do whole element resolution /// internal override void ResolveTopLevelNames() { base.ResolveTopLevelNames(); foreach ( RelationshipEnd end in Ends ) end.ResolveTopLevelNames(); foreach (ReferentialConstraint referentialConstraint in Constraints) { referentialConstraint.ResolveTopLevelNames(); } } protected override bool HandleElement(XmlReader reader) { if (base.HandleElement(reader)) { return true; } else if (CanHandleElement(reader, XmlConstants.End)) { HandleEndElement(reader); return true; } else if (CanHandleElement(reader, XmlConstants.ReferentialConstraint)) { HandleConstraintElement(reader); return true; } return false; } ////// handle the End child element /// /// XmlReader positioned at the end element private void HandleEndElement(XmlReader reader) { Debug.Assert(reader != null); RelationshipEnd end = new RelationshipEnd(this); end.Parse(reader); if (Ends.Count == 2) { AddError( ErrorCode.InvalidAssociation, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.TooManyAssociationEnds(FQName ) ); return; } Ends.Add(end); } ////// handle the constraint element /// /// XmlReader positioned at the constraint element private void HandleConstraintElement(XmlReader reader) { Debug.Assert(reader != null); ReferentialConstraint constraint = new ReferentialConstraint(this); constraint.Parse(reader); this.Constraints.Add(constraint); if (this.Schema.DataModel == SchemaDataModelOption.EntityDataModel && this.Schema.SchemaVersion >= XmlConstants.EdmVersionForV2) { // in V2, referential constraint implies foreign key _isForeignKey = true; } } } } // 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
- XhtmlTextWriter.cs
- BindingEntityInfo.cs
- DataGridViewImageCell.cs
- StorageComplexTypeMapping.cs
- CommandEventArgs.cs
- ServicePoint.cs
- ReferencedAssembly.cs
- TextDecoration.cs
- NotifyIcon.cs
- BrowserCapabilitiesCompiler.cs
- LassoSelectionBehavior.cs
- PolyLineSegment.cs
- SmtpSpecifiedPickupDirectoryElement.cs
- DynamicQueryableWrapper.cs
- SwitchElementsCollection.cs
- DatePicker.cs
- SystemKeyConverter.cs
- DEREncoding.cs
- CngProvider.cs
- PhoneCallDesigner.cs
- ListViewHitTestInfo.cs
- BinaryKeyIdentifierClause.cs
- DataTable.cs
- ApplyTemplatesAction.cs
- RawKeyboardInputReport.cs
- OdbcException.cs
- DbConnectionPoolIdentity.cs
- DbParameterHelper.cs
- SplashScreen.cs
- XPathSingletonIterator.cs
- SpellerInterop.cs
- BitmapDecoder.cs
- VisualStateChangedEventArgs.cs
- XmlCharacterData.cs
- InvalidDocumentContentsException.cs
- TreeNodeEventArgs.cs
- DictionaryBase.cs
- FieldMetadata.cs
- SystemWebSectionGroup.cs
- ProvidePropertyAttribute.cs
- FontStretchConverter.cs
- IPipelineRuntime.cs
- SHA512.cs
- WpfSharedBamlSchemaContext.cs
- DBConcurrencyException.cs
- XappLauncher.cs
- CodeTypeParameterCollection.cs
- EndpointBehaviorElement.cs
- TextServicesDisplayAttributePropertyRanges.cs
- BitmapFrameDecode.cs
- DataGridSortCommandEventArgs.cs
- Vector3DAnimationBase.cs
- DBNull.cs
- UrlAuthFailedErrorFormatter.cs
- IndicShape.cs
- ParameterCollection.cs
- HMACSHA384.cs
- UIElement3DAutomationPeer.cs
- WebPartCancelEventArgs.cs
- ImageSourceValueSerializer.cs
- OdbcParameterCollection.cs
- ToolStripSystemRenderer.cs
- DataGridViewAutoSizeModeEventArgs.cs
- HtmlTitle.cs
- DocumentViewerBaseAutomationPeer.cs
- DesigntimeLicenseContext.cs
- XmlMemberMapping.cs
- XsdCachingReader.cs
- BaseCollection.cs
- ProfilePropertyNameValidator.cs
- clipboard.cs
- FileDialogPermission.cs
- TrackingConditionCollection.cs
- Function.cs
- ITreeGenerator.cs
- SerialPinChanges.cs
- RequiredAttributeAttribute.cs
- TypedAsyncResult.cs
- TreeChangeInfo.cs
- HwndSubclass.cs
- ErrorFormatterPage.cs
- ACE.cs
- TextParaClient.cs
- FormViewUpdatedEventArgs.cs
- Transform3DGroup.cs
- OracleRowUpdatedEventArgs.cs
- XmlSchemaResource.cs
- EditCommandColumn.cs
- ModelUIElement3D.cs
- ColumnClickEvent.cs
- CompilationSection.cs
- FixedPageStructure.cs
- DefaultAssemblyResolver.cs
- EventOpcode.cs
- DataControlImageButton.cs
- LostFocusEventManager.cs
- And.cs
- CacheSection.cs
- EnumDataContract.cs
- TagMapCollection.cs