Files
acceptance-tests
data
debian
docs
external
ikvm-native
libgc
llvm
m4
man
mcs
build
class
Accessibility
Commons.Xml.Relaxng
Cscompmgd
CustomMarshalers
Facades
I18N
IBM.Data.DB2
ICSharpCode.SharpZipLib
Microsoft.Build
Microsoft.Build.Engine
Microsoft.Build.Framework
Microsoft.Build.Tasks
Microsoft.Build.Utilities
Microsoft.CSharp
Microsoft.NuGet.Build.Tasks
Microsoft.VisualC
Microsoft.Web.Infrastructure
MicrosoftAjaxLibrary
Mono.Btls.Interface
Mono.C5
Mono.CSharp
Mono.Cairo
Mono.Cecil
Mono.Cecil.Mdb
Mono.CodeContracts
Mono.CompilerServices.SymbolWriter
Mono.Data.Sqlite
Mono.Data.Tds
Mono.Debugger.Soft
Mono.Http
Mono.Management
Mono.Messaging
Mono.Messaging.RabbitMQ
Mono.Options
Mono.Parallel
Mono.Posix
Mono.Profiler.Log
Mono.Runtime.Tests
Mono.Security
Mono.Security.Win32
Mono.Simd
Mono.Tasklets
Mono.WebBrowser
Mono.XBuild.Tasks
Novell.Directory.Ldap
PEAPI
RabbitMQ.Client
SMDiagnostics
System
System.ComponentModel.Composition.4.5
System.ComponentModel.DataAnnotations
System.Configuration
System.Configuration.Install
System.Core
System.Data
System.Data.DataSetExtensions
System.Data.Entity
System.Data.Linq
System.Data.OracleClient
System.Data.Services
System.Data.Services.Client
System.Deployment
System.Design
System.DirectoryServices
System.DirectoryServices.Protocols
System.Drawing
System.Drawing.Design
System.Dynamic
System.EnterpriseServices
System.IO.Compression
System.IO.Compression.FileSystem
System.IdentityModel
System.IdentityModel.Selectors
System.Json
System.Json.Microsoft
System.Management
System.Messaging
System.Net
System.Net.Http
System.Net.Http.Formatting
System.Net.Http.WebRequest
System.Net.Http.WinHttpHandler
System.Numerics
System.Numerics.Vectors
System.Reactive.Core
System.Reactive.Debugger
System.Reactive.Experimental
System.Reactive.Interfaces
System.Reactive.Linq
System.Reactive.Observable.Aliases
System.Reactive.PlatformServices
System.Reactive.Providers
System.Reactive.Runtime.Remoting
System.Reactive.Windows.Forms
System.Reactive.Windows.Threading
System.Reflection.Context
System.Runtime.Caching
System.Runtime.CompilerServices.Unsafe
System.Runtime.DurableInstancing
System.Runtime.Remoting
System.Runtime.Serialization
System.Runtime.Serialization.Formatters.Soap
System.Security
System.ServiceModel
System.ServiceModel.Activation
System.ServiceModel.Discovery
System.ServiceModel.Internals
System.ServiceModel.Routing
System.ServiceModel.Web
System.ServiceProcess
System.Threading.Tasks.Dataflow
System.Transactions
System.Web
System.Web.Abstractions
System.Web.ApplicationServices
System.Web.DynamicData
System.Web.Extensions
System.Web.Extensions.Design
System.Web.Http
System.Web.Http.SelfHost
System.Web.Http.WebHost
System.Web.Mobile
System.Web.Mvc3
System.Web.Razor
System.Web.RegularExpressions
System.Web.Routing
System.Web.Services
System.Web.WebPages
System.Web.WebPages.Deployment
System.Web.WebPages.Razor
System.Windows
System.Windows.Forms
System.Windows.Forms.DataVisualization
System.Workflow.Activities
System.Workflow.ComponentModel
System.Workflow.Runtime
System.XML
System.Xaml
System.Xml.Linq
System.Xml.Serialization
SystemWebTestShim
WebMatrix.Data
WindowsBase
aot-compiler
corlib
dlr
doc
legacy
lib
monodoc
notes
reference-assemblies
referencesource
SMDiagnostics
System
System.Activities
System.Activities.Core.Presentation
System.Activities.DurableInstancing
System.Activities.Presentation
System.ComponentModel.DataAnnotations
System.Configuration
System.Core
System.Data
System.Data.DataSetExtensions
System.Data.Entity
System
Data
Common
EntityClient
EntityModel
SchemaObjectModel
Action.cs
BooleanFacetDescriptionElement.cs
ByteFacetDescriptionElement.cs
CollectionKind.cs
CollectionTypeElement.cs
ConcurrencyMode.cs
Documentation.cs
EntityContainer.cs
EntityContainerAssociationSet.cs
EntityContainerAssociationSetEnd.cs
EntityContainerEntitySet.cs
EntityContainerEntitySetDefiningQuery.cs
EntityContainerRelationshipSet.cs
EntityContainerRelationshipSetEnd.cs
EntityKeyElement.cs
ErrorCode.cs
FacetDescriptionElement.cs
FacetEnabledSchemaElement.cs
FilteredSchemaElementLookUpTable.cs
Function.cs
FunctionCommandText.cs
FunctionImportElement.cs
IRelationship.cs
IRelationshipEnd.cs
ISchemaElementLookUpTable.cs
IntegerFacetDescriptionElement.cs
ItemType.cs
KeyProperty.cs
ModelFunction.cs
ModelFunctionTypeElement.cs
NavigationProperty.cs
OnOperation.cs
Operation.cs
Parameter.cs
PrimitiveSchema.cs
Property.cs
ReferenceSchema.cs
ReferenceTypeElement.cs
ReferentialConstraint.cs
ReferentialConstraintRoleElement.cs
Relationship.cs
RelationshipEnd.cs
RelationshipEndCollection.cs
ReturnType.cs
ReturnValue.cs
RowTypeElement.cs
RowTypePropertyElement.cs
ScalarType.cs
Schema.cs
SchemaComplexType.cs
SchemaDataModelOption.cs
SchemaElement.cs
SchemaElementLookUpTable.cs
SchemaElementLookUpTableEnumerator.cs
SchemaEnumMember.cs
SchemaEnumType.cs
SchemaLookupTable.cs
SchemaManager.cs
SchemaType.cs
SridFacetDescriptionElement.cs
StoreGeneratedPattern.cs
StructuredProperty.cs
StructuredType.cs
TextElement.cs
TypeElement.cs
TypeModifier.cs
TypeRefElement.cs
TypeUsageBuilder.cs
Utils.cs
ValidationHelper.cs
XmlSchemaResource.cs
Mapping
Metadata
Objects
Query
Spatial
SqlClient
EntityCommandCompilationException.cs
EntityCommandExecutionException.cs
EntityException.cs
EntityKey.cs
EntitySqlException.cs
EntityState.cs
IEntityAdapter.cs
IEntityStateEntry.cs
IEntityStateManager.cs
IExtendedDataRecord.cs
InternalMappingException.cs
InvalidCommandTreeException.cs
MappingException.cs
MetadataException.cs
ObjectNotFoundException.cs
OptimisticConcurrencyException.cs
PropertyConstraintException.cs
ProviderIncompatibleException.cs
UpdateException.cs
Util
misc
GlobalSuppressions.cs
System.Data.Entity.txt.REMOVED.git-id
System.Data.Entity.Design
System.Data.Linq
System.Data.SqlXml
System.IdentityModel
System.IdentityModel.Selectors
System.Net
System.Numerics
System.Runtime.Caching
System.Runtime.DurableInstancing
System.Runtime.Serialization
System.ServiceModel
System.ServiceModel.Activation
System.ServiceModel.Activities
System.ServiceModel.Channels
System.ServiceModel.Discovery
System.ServiceModel.Internals
System.ServiceModel.Routing
System.ServiceModel.WasHosting
System.ServiceModel.Web
System.Web
System.Web.ApplicationServices
System.Web.DataVisualization
System.Web.DynamicData
System.Web.Entity
System.Web.Entity.Design
System.Web.Extensions
System.Web.Mobile
System.Web.Routing
System.Web.Services
System.Workflow.Activities
System.Workflow.ComponentModel
System.Workflow.Runtime
System.WorkflowServices
System.Xaml.Hosting
System.Xml
System.Xml.Linq
XamlBuildTask
mscorlib
LICENSE.txt
PATENTS.TXT
README.Mono.md
README.md
test-helpers
LICENSE
Makefile
Open.snk
README
ecma.pub
mono.pub
mono.snk
msfinal.pub
reactive.pub
silverlight.pub
winfx.pub
winfx3.pub
docs
errors
ilasm
jay
mcs
nunit24
packages
tests
tools
AUTHORS
COPYING
INSTALL.txt
Makefile
MonoIcon.png
README
ScalableMonoIcon.svg
mkinstalldirs
mk
mono
msvc
po
runtime
samples
scripts
support
tools
COPYING.LIB
LICENSE
Makefile.am
Makefile.in
NEWS
README.md
acinclude.m4
aclocal.m4
autogen.sh
code_of_conduct.md
compile
config.guess
config.h.in
config.rpath
config.sub
configure.REMOVED.git-id
configure.ac.REMOVED.git-id
depcomp
install-sh
ltmain.sh.REMOVED.git-id
missing
mkinstalldirs
mono-uninstalled.pc.in
test-driver
winconfig.h
Xamarin Public Jenkins (auto-signing) 536cd135cc Imported Upstream version 5.4.0.167
Former-commit-id: 5624ac747d633e885131e8349322922b6a59baaa
2017-08-21 15:34:15 +00:00

289 lines
9.3 KiB
C#

//---------------------------------------------------------------------
// <copyright file="RelationshipEnd.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//
// @owner Microsoft
// @backupOwner Microsoft
//---------------------------------------------------------------------
namespace System.Data.EntityModel.SchemaObjectModel
{
using System.Collections.Generic;
using System.Data.Metadata.Edm;
using System.Diagnostics;
using System.Xml;
/// <summary>
/// Represents an End element in a relationship
/// </summary>
internal sealed class RelationshipEnd : SchemaElement, IRelationshipEnd
{
private string _unresolvedType;
private RelationshipMultiplicity? _multiplicity;
private SchemaEntityType _type;
private List<OnOperation> _operations;
/// <summary>
/// construct a Relationship End
/// </summary>
/// <param name="relationship"></param>
public RelationshipEnd(Relationship relationship)
: base(relationship)
{
}
/// <summary>
/// Type of the End
/// </summary>
public SchemaEntityType Type
{
get
{
return _type;
}
private set
{
_type = value;
}
}
/// <summary>
/// Multiplicity of the End
/// </summary>
public RelationshipMultiplicity? Multiplicity
{
get
{
return _multiplicity;
}
set
{
_multiplicity = value;
}
}
/// <summary>
/// The On&lt;Operation&gt;s defined for the End
/// </summary>
public ICollection<OnOperation> Operations
{
get
{
if (_operations == null)
_operations = new List<OnOperation>();
return _operations;
}
}
/// <summary>
/// do whole element resolution
/// </summary>
internal override void ResolveTopLevelNames()
{
base.ResolveTopLevelNames();
if (Type == null && _unresolvedType != null)
{
SchemaType element;
if (!Schema.ResolveTypeName(this, _unresolvedType, out element))
{
return;
}
Type = element as SchemaEntityType;
if (Type == null)
{
AddError(ErrorCode.InvalidRelationshipEndType, EdmSchemaErrorSeverity.Error,
System.Data.Entity.Strings.InvalidRelationshipEndType(ParentElement.Name, element.FQName));
}
}
}
internal override void Validate()
{
base.Validate();
// Check if the end has multiplicity as many, it cannot have any operation behaviour
if (Multiplicity == RelationshipMultiplicity.Many && Operations.Count != 0)
{
AddError(ErrorCode.EndWithManyMultiplicityCannotHaveOperationsSpecified,
EdmSchemaErrorSeverity.Error,
System.Data.Entity.Strings.EndWithManyMultiplicityCannotHaveOperationsSpecified(this.Name, ParentElement.FQName));
}
// if there is no RefConstraint in Association and multiplicity is null
if (this.ParentElement.Constraints.Count == 0 && Multiplicity == null)
{
AddError(ErrorCode.EndWithoutMultiplicity,
EdmSchemaErrorSeverity.Error,
System.Data.Entity.Strings.EndWithoutMultiplicity(this.Name, ParentElement.FQName));
}
}
/// <summary>
/// Do simple validation across attributes
/// </summary>
protected override void HandleAttributesComplete()
{
// set up the default name in before validating anythig that might want to display it in an error message;
if (Name == null && _unresolvedType != null)
Name = Utils.ExtractTypeName(Schema.DataModel, _unresolvedType);
base.HandleAttributesComplete();
}
protected override bool ProhibitAttribute(string namespaceUri, string localName)
{
if (base.ProhibitAttribute(namespaceUri, localName))
{
return true;
}
if (namespaceUri == null && localName == XmlConstants.Name)
{
return false;
}
return false;
}
protected override bool HandleAttribute(XmlReader reader)
{
if (base.HandleAttribute(reader))
{
return true;
}
else if (CanHandleAttribute(reader, XmlConstants.Multiplicity))
{
HandleMultiplicityAttribute(reader);
return true;
}
else if (CanHandleAttribute(reader, XmlConstants.Role))
{
HandleNameAttribute(reader);
return true;
}
else if (CanHandleAttribute(reader, XmlConstants.TypeElement))
{
HandleTypeAttribute(reader);
return true;
}
return false;
}
protected override bool HandleElement(XmlReader reader)
{
if (base.HandleElement(reader))
{
return true;
}
else if (CanHandleElement(reader, XmlConstants.OnDelete))
{
HandleOnDeleteElement(reader);
return true;
}
return false;
}
/// <summary>
/// Handle the Type attribute
/// </summary>
/// <param name="reader">reader positioned at Type attribute</param>
private void HandleTypeAttribute(XmlReader reader)
{
Debug.Assert(reader != null);
string type;
if (!Utils.GetDottedName(this.Schema, reader, out type))
return;
_unresolvedType = type;
}
/// <summary>
/// Handle the Multiplicity attribute
/// </summary>
/// <param name="reader">reader positioned at Type attribute</param>
private void HandleMultiplicityAttribute(XmlReader reader)
{
Debug.Assert(reader != null);
RelationshipMultiplicity multiplicity;
if (!TryParseMultiplicity(reader.Value, out multiplicity))
{
AddError(ErrorCode.InvalidMultiplicity, EdmSchemaErrorSeverity.Error, reader, System.Data.Entity.Strings.InvalidRelationshipEndMultiplicity(ParentElement.Name, reader.Value));
}
_multiplicity = multiplicity;
}
/// <summary>
/// Handle an OnDelete element
/// </summary>
/// <param name="reader">reader positioned at the element</param>
private void HandleOnDeleteElement(XmlReader reader)
{
HandleOnOperationElement(reader, Operation.Delete);
}
/// <summary>
/// Handle an On&lt;Operation&gt; element
/// </summary>
/// <param name="reader">reader positioned at the element</param>
/// <param name="operation">the kind of operation being handled</param>
private void HandleOnOperationElement(XmlReader reader, Operation operation)
{
Debug.Assert(reader != null);
foreach (OnOperation other in Operations)
{
if (other.Operation == operation)
AddError(ErrorCode.InvalidOperation, EdmSchemaErrorSeverity.Error, reader, System.Data.Entity.Strings.DuplicationOperation(reader.Name));
}
OnOperation onOperation = new OnOperation(this, operation);
onOperation.Parse(reader);
_operations.Add(onOperation);
}
/// <summary>
/// The parent element as an IRelationship
/// </summary>
internal new IRelationship ParentElement
{
get
{
return (IRelationship)(base.ParentElement);
}
}
/// <summary>
/// Create a new Multiplicity object from a string
/// </summary>
/// <param name="value">string containing Multiplicity definition</param>
/// <param name="multiplicity">new multiplicity object (null if there were errors)</param>
/// <returns>try if the string was parsable, false otherwise</returns>
private static bool TryParseMultiplicity(string value, out RelationshipMultiplicity multiplicity)
{
switch (value)
{
case "0..1":
multiplicity = RelationshipMultiplicity.ZeroOrOne;
return true;
case "1":
multiplicity = RelationshipMultiplicity.One;
return true;
case "*":
multiplicity = RelationshipMultiplicity.Many;
return true;
default:
multiplicity = (RelationshipMultiplicity)(- 1);
return false;
}
}
}
}