Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntity / System / Data / EntityModel / SchemaObjectModel / NavigationProperty.cs / 1305376 / NavigationProperty.cs
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Xml;
using System.Data;
using System.Data.Metadata.Edm;
using System.Diagnostics;
using System.Globalization;
namespace System.Data.EntityModel.SchemaObjectModel
{
///
/// Summary description for Association.
///
[System.Diagnostics.DebuggerDisplay("Name={Name}, Relationship={_unresolvedRelationshipName}, FromRole={_unresolvedFromEndRole}, ToRole={_unresolvedToEndRole}")]
internal sealed class NavigationProperty : Property
{
private string _unresolvedFromEndRole = null;
private string _unresolvedToEndRole = null;
private string _unresolvedRelationshipName = null;
private IRelationshipEnd _fromEnd = null;
private IRelationshipEnd _toEnd = null;
private IRelationship _relationship = null;
///
///
///
///
public NavigationProperty(SchemaEntityType parent)
: base(parent)
{
}
///
///
///
public new SchemaEntityType ParentElement
{
get
{
return base.ParentElement as SchemaEntityType;
}
}
internal IRelationship Relationship
{
get { return _relationship; }
}
internal IRelationshipEnd ToEnd
{
get { return _toEnd; }
}
internal IRelationshipEnd FromEnd
{
get { return _fromEnd; }
}
///
/// Gets the Type of the property
///
public override SchemaType Type
{
get
{
if (_toEnd == null || _toEnd.Type == null)
{
return null;
}
return _toEnd.Type;
}
}
protected override bool HandleAttribute(XmlReader reader)
{
if (base.HandleAttribute(reader))
{
return true;
}
else if (CanHandleAttribute(reader, XmlConstants.Relationship))
{
HandleAssociationAttribute(reader);
return true;
}
else if (CanHandleAttribute(reader, XmlConstants.FromRole))
{
HandleFromRoleAttribute(reader);
return true;
}
else if (CanHandleAttribute(reader, XmlConstants.ToRole))
{
HandleToRoleAttribute(reader);
return true;
}
return false;
}
///
///
///
internal override void ResolveTopLevelNames()
{
base.ResolveTopLevelNames();
SchemaType element;
if (!Schema.ResolveTypeName(this, _unresolvedRelationshipName, out element))
return;
_relationship = element as IRelationship;
if (_relationship == null)
{
AddError(ErrorCode.BadNavigationProperty, EdmSchemaErrorSeverity.Error,
System.Data.Entity.Strings.BadNavigationPropertyRelationshipNotRelationship(_unresolvedRelationshipName));
return;
}
bool foundBothEnds = true;
if (!_relationship.TryGetEnd(_unresolvedFromEndRole, out _fromEnd))
{
AddError(ErrorCode.BadNavigationProperty, EdmSchemaErrorSeverity.Error,
System.Data.Entity.Strings.BadNavigationPropertyUndefinedRole(_unresolvedFromEndRole, _relationship.FQName));
foundBothEnds = false;
}
if (!_relationship.TryGetEnd(_unresolvedToEndRole, out _toEnd))
{
AddError(ErrorCode.BadNavigationProperty, EdmSchemaErrorSeverity.Error,
System.Data.Entity.Strings.BadNavigationPropertyUndefinedRole(_unresolvedToEndRole, _relationship.FQName));
foundBothEnds = false;
}
if (foundBothEnds && _fromEnd == _toEnd)
{
AddError(ErrorCode.BadNavigationProperty, EdmSchemaErrorSeverity.Error,
System.Data.Entity.Strings.BadNavigationPropertyRolesCannotBeTheSame);
}
}
///
///
///
internal override void Validate()
{
base.Validate();
System.Diagnostics.Debug.Assert(_fromEnd != null && _toEnd != null,
"FromEnd and ToEnd must not be null in Validate. ResolveNames must have resolved it or added error");
if (_fromEnd.Type != ParentElement)
{
AddError(ErrorCode.BadNavigationProperty, EdmSchemaErrorSeverity.Error,
System.Data.Entity.Strings.BadNavigationPropertyBadFromRoleType(this.Name,
_fromEnd.Type.FQName, _fromEnd.Name, _relationship.FQName, ParentElement.FQName));
}
StructuredType type = _toEnd.Type;
}
#region Private Methods
///
///
///
///
private void HandleToRoleAttribute(XmlReader reader)
{
_unresolvedToEndRole = HandleUndottedNameAttribute(reader, _unresolvedToEndRole);
}
///
///
///
///
private void HandleFromRoleAttribute(XmlReader reader)
{
_unresolvedFromEndRole = HandleUndottedNameAttribute(reader, _unresolvedFromEndRole);
}
///
///
///
///
private void HandleAssociationAttribute(XmlReader reader)
{
Debug.Assert(_unresolvedRelationshipName == null, string.Format(CultureInfo.CurrentCulture, "{0} is already defined", reader.Name));
string association;
if (!Utils.GetDottedName(this.Schema, reader, out association))
return;
_unresolvedRelationshipName = association;
}
#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
- LogRestartAreaEnumerator.cs
- CompilationUtil.cs
- CannotUnloadAppDomainException.cs
- ParameterElement.cs
- SchemaInfo.cs
- TransportChannelListener.cs
- XmlDownloadManager.cs
- DesignTableCollection.cs
- AxisAngleRotation3D.cs
- FunctionNode.cs
- BStrWrapper.cs
- AttachedPropertyInfo.cs
- HostingMessageProperty.cs
- MarkupCompiler.cs
- ScriptingProfileServiceSection.cs
- StaticResourceExtension.cs
- _SpnDictionary.cs
- ServiceModelExtensionCollectionElement.cs
- ImageCodecInfo.cs
- HostProtectionPermission.cs
- RsaSecurityTokenAuthenticator.cs
- mediapermission.cs
- ExpandCollapsePattern.cs
- XpsPackagingException.cs
- ITextView.cs
- ProjectionCamera.cs
- BrowserCapabilitiesCompiler.cs
- QilStrConcat.cs
- GenericXmlSecurityToken.cs
- SegmentInfo.cs
- ObjectTokenCategory.cs
- UdpMessageProperty.cs
- ListBoxItem.cs
- OleDbCommandBuilder.cs
- PanelStyle.cs
- AncillaryOps.cs
- XhtmlBasicFormAdapter.cs
- XmlSchemaElement.cs
- CompilerLocalReference.cs
- ToolboxComponentsCreatingEventArgs.cs
- _IPv6Address.cs
- GridLength.cs
- PasswordRecovery.cs
- EventLogTraceListener.cs
- AutomationPropertyInfo.cs
- DesignSurfaceCollection.cs
- DataViewSettingCollection.cs
- GridViewColumnHeader.cs
- InputProcessorProfilesLoader.cs
- DataGridViewIntLinkedList.cs
- BezierSegment.cs
- OverrideMode.cs
- Utils.cs
- RightsManagementInformation.cs
- XamlReader.cs
- ObjectMemberMapping.cs
- AncillaryOps.cs
- ElementProxy.cs
- GZipStream.cs
- Int16Storage.cs
- SubMenuStyleCollection.cs
- InputProcessorProfilesLoader.cs
- HttpFileCollection.cs
- SRGSCompiler.cs
- EntityDataSourceDesignerHelper.cs
- TextTrailingWordEllipsis.cs
- XXXInfos.cs
- CompoundFileStreamReference.cs
- HtmlElementErrorEventArgs.cs
- TraceSection.cs
- EntityCommandDefinition.cs
- WebControl.cs
- TextBlock.cs
- hresults.cs
- ExpressionBuilder.cs
- RsaEndpointIdentity.cs
- NumberSubstitution.cs
- RightsManagementEncryptionTransform.cs
- X509Extension.cs
- TypeInfo.cs
- CRYPTPROTECT_PROMPTSTRUCT.cs
- ItemsControlAutomationPeer.cs
- SerialStream.cs
- QilInvokeEarlyBound.cs
- ClassicBorderDecorator.cs
- FixedSOMPage.cs
- CompiledQueryCacheEntry.cs
- ImageSourceValueSerializer.cs
- SlipBehavior.cs
- FormParameter.cs
- PrePrepareMethodAttribute.cs
- RoleBoolean.cs
- ColorPalette.cs
- ScalarRestriction.cs
- LinqDataSourceEditData.cs
- ObjectDataSourceStatusEventArgs.cs
- ComboBoxItem.cs
- SingleAnimation.cs
- DecimalAnimationBase.cs