Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / ndp / fx / src / DataEntity / System / Data / EntityModel / SchemaObjectModel / Relationship.cs / 3 / 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;
RelationshipEndCollection _ends;
private List _constraints;
///
/// Construct a Relationship object
///
/// the parent
/// the kind of relationship
public Relationship(Schema parent, RelationshipKind kind)
: base(parent)
{
RelationshipKind = kind;
}
///
/// List of Ends defined for this Association
///
public IList Ends
{
get
{
if ( _ends == null )
_ends = new RelationshipEndCollection();
return _ends;
}
}
///
/// Returns the list of constraints on this relation
///
public IList Constraints
{
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;
}
}
///
/// 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 &&
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);
}
}
}
// 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;
RelationshipEndCollection _ends;
private List _constraints;
///
/// Construct a Relationship object
///
/// the parent
/// the kind of relationship
public Relationship(Schema parent, RelationshipKind kind)
: base(parent)
{
RelationshipKind = kind;
}
///
/// List of Ends defined for this Association
///
public IList Ends
{
get
{
if ( _ends == null )
_ends = new RelationshipEndCollection();
return _ends;
}
}
///
/// Returns the list of constraints on this relation
///
public IList Constraints
{
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;
}
}
///
/// 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 &&
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);
}
}
}
// 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
- HostingEnvironment.cs
- PlatformNotSupportedException.cs
- SessionIDManager.cs
- MSG.cs
- StatusBarPanel.cs
- WinInetCache.cs
- JsonReader.cs
- HostedHttpTransportManager.cs
- NonClientArea.cs
- DBBindings.cs
- EmbeddedMailObjectsCollection.cs
- QilXmlWriter.cs
- CookieHandler.cs
- RoutingBehavior.cs
- CustomAttributeBuilder.cs
- PrintDialog.cs
- InstanceKeyCollisionException.cs
- HybridObjectCache.cs
- ApplicationFileParser.cs
- AuthenticationServiceManager.cs
- ToolboxItemImageConverter.cs
- Int64AnimationUsingKeyFrames.cs
- GetIndexBinder.cs
- glyphs.cs
- ListViewTableRow.cs
- MailSettingsSection.cs
- StrokeFIndices.cs
- FontUnitConverter.cs
- ListArgumentProvider.cs
- FrameworkObject.cs
- ToolStripPanelSelectionBehavior.cs
- ITreeGenerator.cs
- Pen.cs
- ProfileEventArgs.cs
- CodeSnippetStatement.cs
- SspiHelper.cs
- Config.cs
- GlyphTypeface.cs
- WebSysDisplayNameAttribute.cs
- MiniLockedBorderGlyph.cs
- ByteKeyFrameCollection.cs
- PrinterResolution.cs
- ProjectionCamera.cs
- BuilderPropertyEntry.cs
- HwndTarget.cs
- ThreadStartException.cs
- TimeSpanStorage.cs
- SqlTriggerContext.cs
- DiffuseMaterial.cs
- HtmlInputRadioButton.cs
- MenuCommands.cs
- VirtualDirectoryMappingCollection.cs
- ListSortDescriptionCollection.cs
- _BasicClient.cs
- TypeReference.cs
- WindowsAuthenticationEventArgs.cs
- DataGridTextBox.cs
- Compiler.cs
- SamlAssertionKeyIdentifierClause.cs
- ParserStreamGeometryContext.cs
- WaitHandleCannotBeOpenedException.cs
- CodeIdentifier.cs
- WebPartHelpVerb.cs
- CallbackValidator.cs
- BinaryObjectReader.cs
- PassportAuthenticationEventArgs.cs
- Button.cs
- DataSetFieldSchema.cs
- SqlCacheDependencySection.cs
- InputProcessorProfilesLoader.cs
- TCPListener.cs
- XPathDocumentIterator.cs
- Accessible.cs
- GraphicsState.cs
- DesignerProperties.cs
- SqlDataSourceQueryEditorForm.cs
- SoapFormatExtensions.cs
- AsymmetricSignatureDeformatter.cs
- DataPagerFieldItem.cs
- BuildManager.cs
- InfocardClientCredentials.cs
- BaseCodeDomTreeGenerator.cs
- RegexParser.cs
- StringFunctions.cs
- ListViewItemSelectionChangedEvent.cs
- Identifier.cs
- DataGridHeaderBorder.cs
- XmlSerializationReader.cs
- EntityDataSourceContextCreatingEventArgs.cs
- Pens.cs
- RootAction.cs
- TemplateField.cs
- Vector3DIndependentAnimationStorage.cs
- FixedSOMLineRanges.cs
- ClassHandlersStore.cs
- TrustLevel.cs
- RegistryDataKey.cs
- XmlLangPropertyAttribute.cs
- ComPlusInstanceProvider.cs
- PngBitmapEncoder.cs