Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntity / System / Data / EntityModel / SchemaObjectModel / EntityContainerAssociationSetEnd.cs / 1305376 / EntityContainerAssociationSetEnd.cs
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Xml;
using System.Data;
using System.Data.Metadata.Edm;
namespace System.Data.EntityModel.SchemaObjectModel
{
///
/// Represents an element.
///
internal sealed class EntityContainerAssociationSetEnd : EntityContainerRelationshipSetEnd
{
private string _unresolvedRelationshipEndRole;
///
/// Constructs an EntityContainerAssociationSetEnd
///
/// Reference to the schema element.
public EntityContainerAssociationSetEnd( EntityContainerAssociationSet parentElement )
: base( parentElement )
{
}
public string Role
{
get
{
return _unresolvedRelationshipEndRole;
}
set
{
_unresolvedRelationshipEndRole = value;
}
}
public override string Name
{
get
{
return Role;
}
}
protected override bool HandleAttribute(XmlReader reader)
{
if (base.HandleAttribute(reader))
{
return true;
}
else if (CanHandleAttribute(reader, XmlConstants.Role))
{
HandleRoleAttribute(reader);
return true;
}
return false;
}
///
/// This is the method that is called when an Role Attribute is encountered.
///
/// The XmlRead positned at the extent attribute.
private void HandleRoleAttribute( XmlReader reader )
{
_unresolvedRelationshipEndRole = HandleUndottedNameAttribute( reader, _unresolvedRelationshipEndRole );
}
///
/// Used during the resolve phase to resolve the type name to the object that represents that type
///
internal override void ResolveTopLevelNames()
{
base.ResolveTopLevelNames();
// resolve end name to the corosponding relationship end
IRelationship relationship = ParentElement.Relationship;
if ( relationship == null )
{
// error already logged for this
return;
}
}
internal override void ResolveSecondLevelNames()
{
base.ResolveSecondLevelNames();
if (_unresolvedRelationshipEndRole == null && EntitySet != null)
{
// no role provided, infer it
RelationshipEnd = InferRelationshipEnd(EntitySet);
if (RelationshipEnd != null)
{
_unresolvedRelationshipEndRole = RelationshipEnd.Name;
}
}
else if (_unresolvedRelationshipEndRole != null)
{
IRelationship relationship = ParentElement.Relationship;
IRelationshipEnd end;
if (relationship.TryGetEnd(_unresolvedRelationshipEndRole, out end))
{
RelationshipEnd = end;
}
else
{
// couldn't find a matching relationship end for this RelationshipSet end
AddError(ErrorCode.InvalidContainerTypeForEnd, EdmSchemaErrorSeverity.Error,
System.Data.Entity.Strings.InvalidEntityEndName(Role, relationship.FQName));
}
}
}
///
/// If the role name is missing but an entity set is given, figure out what the
/// relationship end should be
///
/// The given EntitySet
/// The appropriate relationship end
private IRelationshipEnd InferRelationshipEnd( EntityContainerEntitySet set )
{
Debug.Assert(set != null, "set parameter is null");
if ( ParentElement.Relationship == null )
{
return null;
}
List possibleEnds = new List();
foreach ( IRelationshipEnd end in ParentElement.Relationship.Ends )
{
if ( set.EntityType.IsOfType( end.Type ) )
{
possibleEnds.Add( end );
}
}
if ( possibleEnds.Count == 1 )
{
return possibleEnds[0];
}
else if ( possibleEnds.Count == 0 )
{
// no matchs
AddError( ErrorCode.FailedInference, EdmSchemaErrorSeverity.Error,
System.Data.Entity.Strings.InferRelationshipEndFailedNoEntitySetMatch(
set.FQName, this.ParentElement.FQName, ParentElement.Relationship.FQName, set.EntityType.FQName, this.ParentElement.ParentElement.FQName ) );
}
else
{
// ambiguous
AddError( ErrorCode.FailedInference, EdmSchemaErrorSeverity.Error,
System.Data.Entity.Strings.InferRelationshipEndAmbiguous(
set.FQName, this.ParentElement.FQName, ParentElement.Relationship.FQName, set.EntityType.FQName, this.ParentElement.ParentElement.FQName));
}
return null;
}
internal override SchemaElement Clone(SchemaElement parentElement)
{
EntityContainerAssociationSetEnd setEnd = new EntityContainerAssociationSetEnd((EntityContainerAssociationSet)parentElement);
setEnd._unresolvedRelationshipEndRole = _unresolvedRelationshipEndRole;
setEnd.EntitySet = this.EntitySet;
return setEnd;
}
}
}
// 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
- AnimationStorage.cs
- XmlTextEncoder.cs
- CreateParams.cs
- DataListItemEventArgs.cs
- UIElementAutomationPeer.cs
- RoutedCommand.cs
- httpstaticobjectscollection.cs
- Codec.cs
- RowTypePropertyElement.cs
- XmlUrlResolver.cs
- RuntimeCompatibilityAttribute.cs
- TextUtf8RawTextWriter.cs
- ColorConvertedBitmapExtension.cs
- OracleParameterBinding.cs
- ModelVisual3D.cs
- SelectorAutomationPeer.cs
- log.cs
- ApplicationContext.cs
- MethodToken.cs
- MissingFieldException.cs
- WebPartVerbCollection.cs
- AssertFilter.cs
- SqlUDTStorage.cs
- RedirectionProxy.cs
- WindowsFormsEditorServiceHelper.cs
- GridViewRowPresenterBase.cs
- ServerValidateEventArgs.cs
- ObjectReferenceStack.cs
- FixedSOMLineRanges.cs
- Subtree.cs
- ToolStripDropTargetManager.cs
- CacheMemory.cs
- WizardStepBase.cs
- FixedTextBuilder.cs
- DoubleAverageAggregationOperator.cs
- CompositeFontFamily.cs
- EventLog.cs
- MatrixCamera.cs
- DataGridViewRowsRemovedEventArgs.cs
- Glyph.cs
- smtppermission.cs
- UInt64Converter.cs
- WSHttpBinding.cs
- WSDualHttpBindingCollectionElement.cs
- UIElement3D.cs
- TextContainerChangeEventArgs.cs
- IdentityNotMappedException.cs
- SrgsGrammarCompiler.cs
- SvcMapFileLoader.cs
- GcHandle.cs
- WebPartConnectionsCloseVerb.cs
- OleDbTransaction.cs
- WebPartsPersonalizationAuthorization.cs
- ExpanderAutomationPeer.cs
- XslCompiledTransform.cs
- ServiceDesigner.xaml.cs
- TripleDES.cs
- TransformerInfoCollection.cs
- InvariantComparer.cs
- XmlAttributeCollection.cs
- ParallelTimeline.cs
- XmlReflectionImporter.cs
- SessionIDManager.cs
- ColorConvertedBitmapExtension.cs
- XsdCachingReader.cs
- QilPatternFactory.cs
- ToolboxDataAttribute.cs
- SingleTagSectionHandler.cs
- BoundField.cs
- HostingEnvironmentSection.cs
- Vertex.cs
- Internal.cs
- PersonalizationProvider.cs
- InvalidComObjectException.cs
- ArrayElementGridEntry.cs
- DbParameterCollection.cs
- DiscreteKeyFrames.cs
- Directory.cs
- ObjectReferenceStack.cs
- DesignerDataConnection.cs
- GZipDecoder.cs
- StreamingContext.cs
- FastEncoderWindow.cs
- XmlHierarchicalEnumerable.cs
- PlainXmlDeserializer.cs
- MouseEventArgs.cs
- WebException.cs
- PropertyEntry.cs
- CharacterMetricsDictionary.cs
- Conditional.cs
- MainMenu.cs
- PseudoWebRequest.cs
- DiagnosticTrace.cs
- EventSourceCreationData.cs
- Dump.cs
- ClonableStack.cs
- SmtpNetworkElement.cs
- SmtpFailedRecipientsException.cs
- KnownTypesProvider.cs
- IsolatedStoragePermission.cs