Imported Upstream version 4.6.0.125

Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2016-08-03 10:59:49 +00:00
parent a569aebcfd
commit e79aa3c0ed
17047 changed files with 3137615 additions and 392334 deletions

View File

@ -0,0 +1,30 @@
//---------------------------------------------------------------------
// <copyright file="Action.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//
// @owner jeffreed
// @backupOwner anpete
//---------------------------------------------------------------------
using System;
namespace System.Data.EntityModel.SchemaObjectModel
{
/// <summary>
/// Valid actions in an On&lt;Operation&gt; element
/// </summary>
enum Action
{
/// <summary>
/// no action
/// </summary>
None,
/// <summary>
/// Cascade to other ends
/// </summary>
Cascade,
}
}

View File

@ -0,0 +1,45 @@
//---------------------------------------------------------------------
// <copyright file="BooleanFacetDescriptionElement.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.Metadata.Edm;
using System.Xml;
using System.Diagnostics;
namespace System.Data.EntityModel.SchemaObjectModel
{
internal sealed class BooleanFacetDescriptionElement : FacetDescriptionElement
{
public BooleanFacetDescriptionElement(TypeElement type, string name)
:base(type, name)
{
}
public override EdmType FacetType
{
get { return MetadataItem.EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Boolean); }
}
/////////////////////////////////////////////////////////////////////
// Attribute Handlers
/// <summary>
/// Handler for the Default attribute
/// </summary>
/// <param name="reader">xml reader currently positioned at Default attribute</param>
protected override void HandleDefaultAttribute(XmlReader reader)
{
bool value = false;
if (HandleBoolAttribute(reader, ref value))
{
DefaultValue = value;
}
}
}
}

View File

@ -0,0 +1,46 @@
//---------------------------------------------------------------------
// <copyright file="ByteFacetDescriptionElement.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.Metadata.Edm;
using System.Xml;
using System.Diagnostics;
namespace System.Data.EntityModel.SchemaObjectModel
{
internal sealed class ByteFacetDescriptionElement : FacetDescriptionElement
{
public ByteFacetDescriptionElement(TypeElement type, string name)
:base(type, name)
{
}
public override EdmType FacetType
{
get { return MetadataItem.EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Byte); }
}
/////////////////////////////////////////////////////////////////////
// Attribute Handlers
/// <summary>
/// Handler for the Default attribute
/// </summary>
/// <param name="reader">xml reader currently positioned at Default attribute</param>
protected override void HandleDefaultAttribute(XmlReader reader)
{
byte value = 0;
if (HandleByteAttribute(reader, ref value))
{
DefaultValue = (Byte)value;
}
}
}
}

View File

@ -0,0 +1,35 @@
//---------------------------------------------------------------------
// <copyright file="CollectionKind.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//
// @owner jeffreed
// @backupOwner anpete
//---------------------------------------------------------------------
using System;
namespace System.Data.Metadata.Edm
{
/// <summary>
/// Kind of collection (applied to Properties)
/// </summary>
public enum CollectionKind
{
/// <summary>
/// Property is not a Collection
/// </summary>
None,
/// <summary>
/// Collection has Bag semantics( unordered and duplicates ok)
/// </summary>
Bag,
/// <summary>
/// Collection has List semantics
/// (Order is deterministic and duplciates ok)
/// </summary>
List,
}
}

View File

@ -0,0 +1,231 @@
//---------------------------------------------------------------------
// <copyright file="CollectionTypeElement.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
namespace System.Data.EntityModel.SchemaObjectModel
{
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Metadata.Edm;
using System.Diagnostics;
using System.Text;
using System.Xml;
using Som = System.Data.EntityModel.SchemaObjectModel;
/// <summary>
/// class representing the Schema element in the schema
/// </summary>
internal class CollectionTypeElement : ModelFunctionTypeElement
{
private ModelFunctionTypeElement _typeSubElement = null;
#region constructor
/// <summary>
///
/// </summary>
/// <param name="parentElement"></param>
internal CollectionTypeElement(SchemaElement parentElement)
: base(parentElement)
{
}
#endregion
internal ModelFunctionTypeElement SubElement
{
get { return _typeSubElement; }
}
protected override bool HandleAttribute(XmlReader reader)
{
if (base.HandleAttribute(reader))
{
return true;
}
else if (CanHandleAttribute(reader, XmlConstants.ElementType))
{
HandleElementTypeAttribute(reader);
return true;
}
return false;
}
protected void HandleElementTypeAttribute(XmlReader reader)
{
Debug.Assert(reader != null);
string type;
if (!Utils.GetString(Schema, reader, out type))
return;
if (!Utils.ValidateDottedName(Schema, reader, type))
return;
_unresolvedType = type;
}
protected override bool HandleElement(XmlReader reader)
{
if (CanHandleElement(reader, XmlConstants.CollectionType))
{
HandleCollectionTypeElement(reader);
return true;
}
else if (CanHandleElement(reader, XmlConstants.ReferenceType))
{
HandleReferenceTypeElement(reader);
return true;
}
else if (CanHandleElement(reader, XmlConstants.TypeRef))
{
HandleTypeRefElement(reader);
return true;
}
else if (CanHandleElement(reader, XmlConstants.RowType))
{
HandleRowTypeElement(reader);
return true;
}
return false;
}
protected void HandleCollectionTypeElement(XmlReader reader)
{
Debug.Assert(reader != null);
var subElement = new CollectionTypeElement(this);
subElement.Parse(reader);
_typeSubElement = subElement;
}
protected void HandleReferenceTypeElement(XmlReader reader)
{
Debug.Assert(reader != null);
var subElement = new ReferenceTypeElement(this);
subElement.Parse(reader);
_typeSubElement = subElement;
}
protected void HandleTypeRefElement(XmlReader reader)
{
Debug.Assert(reader != null);
var subElement = new TypeRefElement(this);
subElement.Parse(reader);
_typeSubElement = subElement;
}
protected void HandleRowTypeElement(XmlReader reader)
{
Debug.Assert(reader != null);
var subElement = new RowTypeElement(this);
subElement.Parse(reader);
_typeSubElement = subElement;
}
internal override void ResolveTopLevelNames()
{
if (_typeSubElement != null)
{
_typeSubElement.ResolveTopLevelNames();
}
// Can't be "else if" because element could have attribute AND sub-element,
// in which case semantic validation won't work unless it has resolved both (so _type is not null)
if( _unresolvedType != null)
{
base.ResolveTopLevelNames();
}
}
internal override void WriteIdentity(StringBuilder builder)
{
if (UnresolvedType != null && !UnresolvedType.Trim().Equals(String.Empty))
{
builder.Append("Collection(" + UnresolvedType + ")");
}
else
{
builder.Append("Collection(");
_typeSubElement.WriteIdentity(builder);
builder.Append(")");
}
}
internal override TypeUsage GetTypeUsage()
{
if (_typeUsage != null)
{
return _typeUsage;
}
Debug.Assert(_typeSubElement != null, "For attributes typeusage should have been resolved");
if (_typeSubElement != null)
{
CollectionType collectionType = new CollectionType(_typeSubElement.GetTypeUsage());
collectionType.AddMetadataProperties(this.OtherContent);
_typeUsage = TypeUsage.Create(collectionType);
}
return _typeUsage;
}
internal override bool ResolveNameAndSetTypeUsage(Converter.ConversionCache convertedItemCache, Dictionary<Som.SchemaElement, GlobalItem> newGlobalItems)
{
if (_typeUsage == null)
{
if (_typeSubElement != null) //Has sub-elements
{
return _typeSubElement.ResolveNameAndSetTypeUsage(convertedItemCache, newGlobalItems);
}
else //Does not have sub-elements; try to resolve
{
if (_type is ScalarType) //Create and store type usage for scalar type
{
_typeUsageBuilder.ValidateAndSetTypeUsage(_type as ScalarType, false);
_typeUsage = TypeUsage.Create(new CollectionType(_typeUsageBuilder.TypeUsage));
return true;
}
else //Try to resolve edm type. If not now, it will resolve in the second pass
{
EdmType edmType = (EdmType)Converter.LoadSchemaElement(_type, _type.Schema.ProviderManifest, convertedItemCache, newGlobalItems);
if (edmType != null)
{
_typeUsageBuilder.ValidateAndSetTypeUsage(edmType, false); //use typeusagebuilder so dont lose facet information
_typeUsage = TypeUsage.Create(new CollectionType(_typeUsageBuilder.TypeUsage));
}
return _typeUsage != null;
}
}
}
return true;
}
internal override void Validate()
{
base.Validate();
ValidationHelper.ValidateFacets(this, _type, _typeUsageBuilder);
ValidationHelper.ValidateTypeDeclaration(this, _type, _typeSubElement);
if (_typeSubElement != null)
{
_typeSubElement.Validate();
}
}
}
}

View File

@ -0,0 +1,31 @@
//---------------------------------------------------------------------
// <copyright file="ConcurrencyMode.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//
// @owner jeffreed
// @backupOwner anpete
//---------------------------------------------------------------------
using System;
namespace System.Data.Metadata.Edm
{
/// <summary>
/// The concurrency mode for properties.
/// </summary>
public enum ConcurrencyMode
{
/// <summary>
/// Default concurrency mode: the property is never validated
/// at write time
/// </summary>
None,
/// <summary>
/// Fixed concurrency mode: the property is always validated at
/// write time
/// </summary>
Fixed,
}
}

View File

@ -0,0 +1,115 @@
//---------------------------------------------------------------------
// <copyright file="Documentation.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
namespace System.Data.EntityModel.SchemaObjectModel
{
using System.Data.Common.Utils;
using System.Data.Metadata.Edm;
using System.Xml;
/// <summary>
/// Summary description for Documentation.
/// </summary>
internal sealed class DocumentationElement: SchemaElement
{
#region Instance Fields
Documentation _metdataDocumentation = new Documentation();
#endregion
#region Public Methods
/// <summary>
///
/// </summary>
/// <param name="parentElement"></param>
public DocumentationElement(SchemaElement parentElement)
: base(parentElement)
{
}
#endregion
#region Public Properties
/// <summary>
/// Returns the wrapped metaDocumentation instance
/// </summary>
public Documentation MetadataDocumentation
{
get
{
_metdataDocumentation.SetReadOnly();
return _metdataDocumentation;
}
}
#endregion
#region Protected Properties
protected override bool HandleElement(XmlReader reader)
{
if (base.HandleElement(reader))
{
return true;
}
else if (CanHandleElement(reader, XmlConstants.Summary))
{
HandleSummaryElement(reader);
return true;
}
else if (CanHandleElement(reader, XmlConstants.LongDescription))
{
HandleLongDescriptionElement(reader);
return true;
}
return false;
}
#endregion
#region Private Methods
protected override bool HandleText(XmlReader reader)
{
string text = reader.Value;
if (!StringUtil.IsNullOrEmptyOrWhiteSpace(text))
{
AddError(ErrorCode.UnexpectedXmlElement, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.InvalidDocumentationBothTextAndStructure);
}
return true;
}
/// <summary>
///
/// </summary>
/// <param name="reader"></param>
private void HandleSummaryElement(XmlReader reader)
{
TextElement text = new TextElement(this);
text.Parse(reader);
_metdataDocumentation.Summary = text.Value;
}
/// <summary>
///
/// </summary>
/// <param name="reader"></param>
private void HandleLongDescriptionElement(XmlReader reader)
{
TextElement text = new TextElement(this);
text.Parse(reader);
_metdataDocumentation.LongDescription = text.Value;
}
#endregion
}
}

View File

@ -0,0 +1,193 @@
//---------------------------------------------------------------------
// <copyright file="EntityContainerAssociationSet.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
namespace System.Data.EntityModel.SchemaObjectModel
{
using System.Collections.Generic;
using System.Data.Metadata.Edm;
using System.Data.Objects.DataClasses;
using System.Diagnostics;
using System.Globalization;
using System.Xml;
/// <summary>
/// Represents an AssociationSet element.
/// </summary>
internal sealed class EntityContainerAssociationSet : EntityContainerRelationshipSet
{
// Note: If you add more fields, please make sure you handle that in the clone method
private Dictionary<string, EntityContainerAssociationSetEnd> _relationshipEnds = new Dictionary<string, EntityContainerAssociationSetEnd>();
private List<EntityContainerAssociationSetEnd> _rolelessEnds = new List<EntityContainerAssociationSetEnd>();
/// <summary>
/// Constructs an EntityContainerAssociationSet
/// </summary>
/// <param name="parentElement">Reference to the schema element.</param>
public EntityContainerAssociationSet( EntityContainer parentElement )
: base( parentElement )
{
}
/// <summary>
/// The ends defined and infered for this AssociationSet
/// </summary>
internal override IEnumerable<EntityContainerRelationshipSetEnd> Ends
{
get
{
foreach ( EntityContainerAssociationSetEnd end in _relationshipEnds.Values )
{
yield return end;
}
foreach ( EntityContainerAssociationSetEnd end in _rolelessEnds )
{
yield return end;
}
}
}
protected override bool HandleAttribute(XmlReader reader)
{
if (base.HandleAttribute(reader))
{
return true;
}
else if (CanHandleAttribute(reader, XmlConstants.Association))
{
HandleRelationshipTypeNameAttribute(reader);
return true;
}
return false;
}
protected override bool HandleElement(XmlReader reader)
{
if (base.HandleElement(reader))
{
return true;
}
else if (CanHandleElement(reader, XmlConstants.End))
{
HandleEndElement(reader);
return true;
}
return false;
}
/// <summary>
/// The method that is called when an End element is encountered.
/// </summary>
/// <param name="reader">The XmlReader positioned at the EndElement.</param>
private void HandleEndElement( XmlReader reader )
{
Debug.Assert( reader != null );
EntityContainerAssociationSetEnd end = new EntityContainerAssociationSetEnd( this );
end.Parse( reader );
if ( end.Role == null )
{
// we will resolve the role name later and put it in the
// normal _relationshipEnds dictionary
_rolelessEnds.Add( end );
return;
}
if ( HasEnd( end.Role ) )
{
end.AddError( ErrorCode.InvalidName, EdmSchemaErrorSeverity.Error, reader,
System.Data.Entity.Strings.DuplicateEndName(end.Name ) );
return;
}
_relationshipEnds.Add( end.Role, end );
}
internal override void ResolveTopLevelNames()
{
base.ResolveTopLevelNames();
// this just got resolved
Debug.Assert(
Relationship == null || Relationship.RelationshipKind == RelationshipKind.Association,
string.Format(CultureInfo.InvariantCulture, "The relationship referenced by the Association attribute of {0} is not an Association relationship.", FQName));
}
internal override void ResolveSecondLevelNames()
{
base.ResolveSecondLevelNames();
// the base class should have fixed up the role names on my ends
foreach (EntityContainerAssociationSetEnd end in _rolelessEnds)
{
if (end.Role != null)
{
if (HasEnd(end.Role))
{
end.AddError(ErrorCode.InvalidName, EdmSchemaErrorSeverity.Error,
System.Data.Entity.Strings.InferRelationshipEndGivesAlreadyDefinedEnd(end.EntitySet.FQName, Name));
}
else
{
_relationshipEnds.Add(end.Role, end);
}
}
// any that didn't get resolved will already have errors entered
}
_rolelessEnds.Clear();
}
/// <summary>
/// Create and add a EntityContainerEnd from the IRelationshipEnd provided
/// </summary>
/// <param name="relationshipEnd">The relationship end of the end to add.</param>
/// <param name="entitySet">The entitySet to associate with the relationship end.</param>
protected override void AddEnd( IRelationshipEnd relationshipEnd, EntityContainerEntitySet entitySet )
{
Debug.Assert( relationshipEnd != null );
Debug.Assert( !_relationshipEnds.ContainsKey( relationshipEnd.Name ) );
// we expect set to be null sometimes
EntityContainerAssociationSetEnd end = new EntityContainerAssociationSetEnd( this );
end.Role = relationshipEnd.Name;
end.RelationshipEnd = relationshipEnd;
end.EntitySet = entitySet;
if ( end.EntitySet != null )
{
_relationshipEnds.Add( end.Role, end );
}
}
protected override bool HasEnd( string role )
{
return _relationshipEnds.ContainsKey( role );
}
internal override SchemaElement Clone(SchemaElement parentElement)
{
EntityContainerAssociationSet associationSet = new EntityContainerAssociationSet((EntityContainer)parentElement);
associationSet.Name = this.Name;
associationSet.Relationship = this.Relationship;
foreach (EntityContainerAssociationSetEnd end in this.Ends)
{
EntityContainerAssociationSetEnd clonedEnd = (EntityContainerAssociationSetEnd)end.Clone(associationSet);
associationSet._relationshipEnds.Add(clonedEnd.Role, clonedEnd);
}
return associationSet;
}
}
}

View File

@ -0,0 +1,182 @@
//---------------------------------------------------------------------
// <copyright file="EntityContainerAssociationSetEnd.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
namespace System.Data.EntityModel.SchemaObjectModel
{
using System.Collections.Generic;
using System.Data.Metadata.Edm;
using System.Diagnostics;
using System.Xml;
/// <summary>
/// Represents an element.
/// </summary>
internal sealed class EntityContainerAssociationSetEnd : EntityContainerRelationshipSetEnd
{
private string _unresolvedRelationshipEndRole;
/// <summary>
/// Constructs an EntityContainerAssociationSetEnd
/// </summary>
/// <param name="parentElement">Reference to the schema element.</param>
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;
}
/// <summary>
/// This is the method that is called when an Role Attribute is encountered.
/// </summary>
/// <param name="reader">The XmlRead positned at the extent attribute.</param>
private void HandleRoleAttribute( XmlReader reader )
{
_unresolvedRelationshipEndRole = HandleUndottedNameAttribute( reader, _unresolvedRelationshipEndRole );
}
/// <summary>
/// Used during the resolve phase to resolve the type name to the object that represents that type
/// </summary>
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));
}
}
}
/// <summary>
/// If the role name is missing but an entity set is given, figure out what the
/// relationship end should be
/// </summary>
/// <param name="set">The given EntitySet</param>
/// <returns>The appropriate relationship end</returns>
private IRelationshipEnd InferRelationshipEnd( EntityContainerEntitySet set )
{
Debug.Assert(set != null, "set parameter is null");
if ( ParentElement.Relationship == null )
{
return null;
}
List<IRelationshipEnd> possibleEnds = new List<IRelationshipEnd>();
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.Name, this.ParentElement.Name, ParentElement.Relationship.FQName, set.EntityType.FQName, this.ParentElement.ParentElement.FQName ) );
}
else
{
// ambiguous
AddError( ErrorCode.FailedInference, EdmSchemaErrorSeverity.Error,
System.Data.Entity.Strings.InferRelationshipEndAmbiguous(
set.Name, this.ParentElement.Name, 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;
}
}
}

View File

@ -0,0 +1,262 @@
//---------------------------------------------------------------------
// <copyright file="EntityContainerEntitySet.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
namespace System.Data.EntityModel.SchemaObjectModel
{
using System.Data.Entity;
using System.Data.Metadata.Edm;
using System.Diagnostics;
using System.Xml;
/// <summary>
/// Represents an EntitySet element.
/// </summary>
internal sealed class EntityContainerEntitySet : SchemaElement
{
private SchemaEntityType _entityType = null;
private string _unresolvedEntityTypeName = null;
private string _schema = null;
private string _table = null;
private EntityContainerEntitySetDefiningQuery _definingQueryElement = null;
/// <summary>
/// Constructs an EntityContainerEntitySet
/// </summary>
/// <param name="parentElement">Reference to the schema element.</param>
public EntityContainerEntitySet( EntityContainer parentElement )
: base( parentElement )
{
}
public override string FQName
{
get
{
return this.ParentElement.Name + "." + this.Name;
}
}
public SchemaEntityType EntityType
{
get
{
return _entityType;
}
}
public string DbSchema
{
get
{
return _schema;
}
}
public string Table
{
get
{
return _table;
}
}
public string DefiningQuery
{
get
{
if (_definingQueryElement != null)
{
return _definingQueryElement.Query;
}
return null;
}
}
protected override bool HandleElement(XmlReader reader)
{
if (base.HandleElement(reader))
{
return true;
}
else if (Schema.DataModel == SchemaDataModelOption.ProviderDataModel)
{
if (CanHandleElement(reader, XmlConstants.DefiningQuery))
{
HandleDefiningQueryElement(reader);
return true;
}
}
else if (Schema.DataModel == SchemaDataModelOption.EntityDataModel)
{
if (CanHandleElement(reader, XmlConstants.ValueAnnotation))
{
// EF does not support this EDM 3.0 element, so ignore it.
SkipElement(reader);
return true;
}
else if (CanHandleElement(reader, XmlConstants.TypeAnnotation))
{
// EF does not support this EDM 3.0 element, so ignore it.
SkipElement(reader);
return true;
}
}
return false;
}
protected override bool HandleAttribute(XmlReader reader)
{
if (base.HandleAttribute(reader))
{
return true;
}
else if (CanHandleAttribute(reader, XmlConstants.EntityType))
{
HandleEntityTypeAttribute(reader);
return true;
}
if (Schema.DataModel == SchemaDataModelOption.ProviderDataModel)
{
if (CanHandleAttribute(reader, XmlConstants.Schema))
{
HandleDbSchemaAttribute(reader);
return true;
}
else if (CanHandleAttribute(reader, XmlConstants.Table))
{
HandleTableAttribute(reader);
return true;
}
}
return false;
}
private void HandleDefiningQueryElement(XmlReader reader)
{
Debug.Assert(reader != null);
EntityContainerEntitySetDefiningQuery query = new EntityContainerEntitySetDefiningQuery(this);
query.Parse(reader);
_definingQueryElement = query;
}
protected override void HandleNameAttribute(XmlReader reader)
{
if (Schema.DataModel == SchemaDataModelOption.ProviderDataModel)
{
// ssdl will take anything, because this is the table name, and we
// can't predict what the vendor will need in a table name
Name = reader.Value;
}
else
{
base.HandleNameAttribute(reader);
}
}
/// <summary>
/// The method that is called when a Type attribute is encountered.
/// </summary>
/// <param name="reader">An XmlReader positioned at the Type attribute.</param>
private void HandleEntityTypeAttribute( XmlReader reader )
{
Debug.Assert( reader != null );
ReturnValue<string> value = HandleDottedNameAttribute( reader, _unresolvedEntityTypeName, Strings.PropertyTypeAlreadyDefined );
if ( value.Succeeded )
{
_unresolvedEntityTypeName = value.Value;
}
}
/// <summary>
/// The method that is called when a DbSchema attribute is encountered.
/// </summary>
/// <param name="reader">An XmlReader positioned at the Type attribute.</param>
private void HandleDbSchemaAttribute( XmlReader reader )
{
Debug.Assert(Schema.DataModel == SchemaDataModelOption.ProviderDataModel, "We shouldn't see this attribute unless we are parsing ssdl");
Debug.Assert( reader != null );
_schema = reader.Value;
}
/// <summary>
/// The method that is called when a DbTable attribute is encountered.
/// </summary>
/// <param name="reader">An XmlReader positioned at the Type attribute.</param>
private void HandleTableAttribute( XmlReader reader )
{
Debug.Assert(Schema.DataModel == SchemaDataModelOption.ProviderDataModel, "We shouldn't see this attribute unless we are parsing ssdl");
Debug.Assert( reader != null );
_table = reader.Value;
}
/// <summary>
/// Used during the resolve phase to resolve the type name to the object that represents that type
/// </summary>
internal override void ResolveTopLevelNames()
{
base.ResolveTopLevelNames();
if ( _entityType == null )
{
SchemaType type = null;
if ( ! Schema.ResolveTypeName( this, _unresolvedEntityTypeName, out type) )
{
return;
}
_entityType = type as SchemaEntityType;
if ( _entityType == null )
{
AddError( ErrorCode.InvalidPropertyType, EdmSchemaErrorSeverity.Error,
System.Data.Entity.Strings.InvalidEntitySetType(_unresolvedEntityTypeName ) );
return;
}
}
}
internal override void Validate()
{
base.Validate();
if (_entityType.KeyProperties.Count == 0)
{
AddError(ErrorCode.EntitySetTypeHasNoKeys, EdmSchemaErrorSeverity.Error,
System.Data.Entity.Strings.EntitySetTypeHasNoKeys(Name, _entityType.FQName));
}
if (_definingQueryElement != null)
{
_definingQueryElement.Validate();
if (DbSchema != null || Table != null)
{
AddError(ErrorCode.TableAndSchemaAreMutuallyExclusiveWithDefiningQuery, EdmSchemaErrorSeverity.Error,
System.Data.Entity.Strings.TableAndSchemaAreMutuallyExclusiveWithDefiningQuery(FQName));
}
}
}
internal override SchemaElement Clone(SchemaElement parentElement)
{
EntityContainerEntitySet entitySet = new EntityContainerEntitySet((EntityContainer)parentElement);
entitySet._definingQueryElement = this._definingQueryElement;
entitySet._entityType = this._entityType;
entitySet._schema = this._schema;
entitySet._table = this._table;
entitySet.Name = this.Name;
return entitySet;
}
}
}

View File

@ -0,0 +1,54 @@
//---------------------------------------------------------------------
// <copyright file="EntityContainerEntitySetDefiningQuery.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
namespace System.Data.EntityModel.SchemaObjectModel
{
using System;
using System.Data.Metadata.Edm;
using System.Xml;
/// <summary>
/// Represents an DefiningQuery element.
/// </summary>
internal sealed class EntityContainerEntitySetDefiningQuery : SchemaElement
{
private string _query;
/// <summary>
/// Constructs an EntityContainerEntitySet
/// </summary>
/// <param name="parentElement">Reference to the schema element.</param>
public EntityContainerEntitySetDefiningQuery(EntityContainerEntitySet parentElement)
: base( parentElement )
{
}
public string Query
{
get { return _query; }
}
protected override bool HandleText(XmlReader reader)
{
_query = reader.Value;
return true;
}
internal override void Validate()
{
base.Validate();
if(String.IsNullOrEmpty(_query))
{
AddError(ErrorCode.EmptyDefiningQuery, EdmSchemaErrorSeverity.Error,
System.Data.Entity.Strings.EmptyDefiningQuery);
}
}
}
}

View File

@ -0,0 +1,231 @@
//---------------------------------------------------------------------
// <copyright file="EntityContainerRelationshipSet.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
namespace System.Data.EntityModel.SchemaObjectModel
{
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Metadata.Edm;
using System.Diagnostics;
using System.Xml;
/// <summary>
/// Represents an RelationshipSet element.
/// </summary>
internal abstract class EntityContainerRelationshipSet : SchemaElement
{
private IRelationship _relationship;
string _unresolvedRelationshipTypeName;
/// <summary>
/// Constructs an EntityContainerRelationshipSet
/// </summary>
/// <param name="parentElement">Reference to the schema element.</param>
public EntityContainerRelationshipSet( EntityContainer parentElement )
: base( parentElement )
{
}
public override string FQName
{
get
{
return this.ParentElement.Name + "." + this.Name;
}
}
internal IRelationship Relationship
{
get
{
return _relationship;
}
set
{
Debug.Assert(value != null, "relationship can never be set to null");
_relationship = value;
}
}
protected abstract bool HasEnd( string role );
protected abstract void AddEnd( IRelationshipEnd relationshipEnd, EntityContainerEntitySet entitySet );
internal abstract IEnumerable<EntityContainerRelationshipSetEnd> Ends { get; }
/// <summary>
/// The method that is called when an Association attribute is encountered.
/// </summary>
/// <param name="reader">An XmlReader positioned at the Association attribute.</param>
protected void HandleRelationshipTypeNameAttribute( XmlReader reader )
{
Debug.Assert( reader != null );
ReturnValue<string> value = HandleDottedNameAttribute( reader, _unresolvedRelationshipTypeName, Strings.PropertyTypeAlreadyDefined );
if ( value.Succeeded )
{
_unresolvedRelationshipTypeName = value.Value;
}
}
/// <summary>
/// Used during the resolve phase to resolve the type name to the object that represents that type
/// </summary>
internal override void ResolveTopLevelNames()
{
base.ResolveTopLevelNames();
if ( _relationship == null )
{
SchemaType element;
if ( !Schema.ResolveTypeName( this, _unresolvedRelationshipTypeName, out element ) )
{
return;
}
_relationship = element as IRelationship;
if ( _relationship == null )
{
AddError( ErrorCode.InvalidPropertyType, EdmSchemaErrorSeverity.Error,
System.Data.Entity.Strings.InvalidRelationshipSetType(element.Name ) );
return;
}
}
foreach ( EntityContainerRelationshipSetEnd end in Ends )
{
end.ResolveTopLevelNames();
}
}
internal override void ResolveSecondLevelNames()
{
base.ResolveSecondLevelNames();
foreach (EntityContainerRelationshipSetEnd end in Ends)
{
end.ResolveSecondLevelNames();
}
}
/// <summary>
/// Do all validation for this element here, and delegate to all sub elements
/// </summary>
internal override void Validate()
{
base.Validate();
InferEnds();
// check out the ends
foreach ( EntityContainerRelationshipSetEnd end in Ends )
{
end.Validate();
}
// Enabling Association between subtypes in case of Referential Constraints, since
// CSD is blocked on this. We need to make a long term call about whether we should
// really allow this. Bug #520216
//foreach (ReferentialConstraint constraint in Relationship.Constraints)
//{
// IRelationshipEnd dependentEnd = constraint.DependentRole.End;
// EntityContainerRelationshipSetEnd setEnd = GetEnd(dependentEnd.Name);
// Debug.Assert(setEnd != null);
// //Make sure that the EntityType of the dependant role in a referential constraint
// //covers the whole EntitySet( i.e. not a subtype of the EntitySet's type).
// if (!setEnd.EntitySet.EntityType.IsOfType(constraint.DependentRole.End.Type))
// {
// AddError(ErrorCode.InvalidDependentRoleType, EdmSchemaErrorSeverity.Error,
// System.Data.Entity.Strings.InvalidDependentRoleType(dependentEnd.Type.FQName, dependentEnd.Name,
// dependentEnd.Parent.FQName, setEnd.EntitySet.Name, setEnd.ParentElement.Name));
// }
//}
// Validate Number of ends is correct
// What we know:
// No ends are missing, becuase we infered all missing ends
// No extra ends are there because the names have been matched, and an extra name will have caused an error
//
// looks like no count validation needs to be done
}
/// <summary>
/// Adds any ends that need to be infered
/// </summary>
private void InferEnds()
{
Debug.Assert( Relationship != null );
foreach ( IRelationshipEnd relationshipEnd in Relationship.Ends )
{
if ( ! HasEnd( relationshipEnd.Name ) )
{
EntityContainerEntitySet entitySet = InferEntitySet(relationshipEnd);
if (entitySet != null)
{
// we don't have this end, we need to add it
AddEnd(relationshipEnd, entitySet);
}
}
}
}
/// <summary>
/// For the given relationship end, find the EntityContainer Property that will work for the extent
/// </summary>
/// <param name="relationshipEnd">The relationship end of the RelationshipSet that needs and extent</param>
/// <returns>Null is none could be found, or the EntityContainerProperty that is the valid extent</returns>
private EntityContainerEntitySet InferEntitySet( IRelationshipEnd relationshipEnd )
{
Debug.Assert(relationshipEnd != null, "relationshipEnd parameter is null");
List<EntityContainerEntitySet> possibleExtents = new List<EntityContainerEntitySet>();
foreach ( EntityContainerEntitySet set in ParentElement.EntitySets )
{
if ( relationshipEnd.Type.IsOfType( set.EntityType ) )
{
possibleExtents.Add( set );
}
}
if ( possibleExtents.Count == 1 )
{
return possibleExtents[0];
}
else if ( possibleExtents.Count == 0 )
{
// no matchs
AddError( ErrorCode.MissingExtentEntityContainerEnd, EdmSchemaErrorSeverity.Error,
System.Data.Entity.Strings.MissingEntityContainerEnd(relationshipEnd.Name, FQName ) );
}
else
{
// abmigous
AddError( ErrorCode.AmbiguousEntityContainerEnd, EdmSchemaErrorSeverity.Error,
System.Data.Entity.Strings.AmbiguousEntityContainerEnd(relationshipEnd.Name, FQName ) );
}
return null;
}
/// <summary>
/// The parent element as an EntityContainer
/// </summary>
internal new EntityContainer ParentElement
{
get
{
return (EntityContainer)( base.ParentElement );
}
}
}
}

View File

@ -0,0 +1,152 @@
//---------------------------------------------------------------------
// <copyright file="EntityContainerRelationshipSetEnd.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
namespace System.Data.EntityModel.SchemaObjectModel
{
using System.Data.Metadata.Edm;
using System.Xml;
/// <summary>
/// Represents an RelationshipSetEnd element.
/// </summary>
internal class EntityContainerRelationshipSetEnd : SchemaElement
{
private IRelationshipEnd _relationshipEnd;
private string _unresolvedEntitySetName;
private EntityContainerEntitySet _entitySet;
/// <summary>
/// Constructs an EntityContainerRelationshipSetEnd
/// </summary>
/// <param name="parentElement">Reference to the schema element.</param>
public EntityContainerRelationshipSetEnd( EntityContainerRelationshipSet parentElement )
: base( parentElement )
{
}
/// <summary>
/// the End in the parent<6E>s Association that this element refers to
/// </summary>
public IRelationshipEnd RelationshipEnd
{
get { return _relationshipEnd; }
internal set { _relationshipEnd = value; }
}
public EntityContainerEntitySet EntitySet
{
get { return _entitySet; }
internal set { _entitySet = value; }
}
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.EntitySet))
{
HandleEntitySetAttribute(reader);
return true;
}
return false;
}
/// <summary>
/// This is the method that is called when an EntitySet Attribute is encountered.
/// </summary>
/// <param name="reader">The XmlRead positned at the extent attribute.</param>
private void HandleEntitySetAttribute( XmlReader reader )
{
if (Schema.DataModel == SchemaDataModelOption.ProviderDataModel)
{
// ssdl will take anything, because this is the table name, and we
// can't predict what the vendor will need in a table name
_unresolvedEntitySetName = reader.Value;
}
else
{
_unresolvedEntitySetName = HandleUndottedNameAttribute(reader, _unresolvedEntitySetName);
}
}
/// <summary>
/// Used during the resolve phase to resolve the type name to the object that represents that type
/// </summary>
internal override void ResolveTopLevelNames()
{
base.ResolveTopLevelNames();
if ( _entitySet == null )
{
_entitySet = this.ParentElement.ParentElement.FindEntitySet( _unresolvedEntitySetName );
if ( _entitySet == null )
{
AddError( ErrorCode.InvalidEndEntitySet, EdmSchemaErrorSeverity.Error,
System.Data.Entity.Strings.InvalidEntitySetNameReference(_unresolvedEntitySetName, Name ) );
}
}
}
/// <summary>
/// Do all validation for this element here, and delegate to all sub elements
/// </summary>
internal override void Validate()
{
base.Validate();
if ( _relationshipEnd == null || _entitySet == null )
{
return;
}
// We need to allow 2 kind of scenarios:
// 1> If you have a relationship type defined between Customer and Order, then you can have a association set in
// which the Customer end refers to a Entity Set of type GoodCustomer where GoodCustomer type derives from Customer
// 2> If you have a relationship type defined between GoodCustomer and Order, then you can have a relationship
// set which GoodCustomer end refers to an entity set whose entity type is Customer (where GoodCustomer derives
// from Customer). This scenario enables us to support scenarios where you want specific types in an entity set
// to take part in a relationship.
if ( !_relationshipEnd.Type.IsOfType( _entitySet.EntityType ) &&
!_entitySet.EntityType.IsOfType( _relationshipEnd.Type ))
{
AddError( ErrorCode.InvalidEndEntitySet, EdmSchemaErrorSeverity.Error,
System.Data.Entity.Strings.InvalidEndEntitySetTypeMismatch(_relationshipEnd.Name ) );
}
}
/// <summary>
/// The parent element as an EntityContainerProperty
/// </summary>
internal new EntityContainerRelationshipSet ParentElement
{
get
{
return (EntityContainerRelationshipSet)( base.ParentElement );
}
}
}
}

View File

@ -0,0 +1,165 @@
//---------------------------------------------------------------------
// <copyright file="EntityKeyElement.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
namespace System.Data.EntityModel.SchemaObjectModel
{
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Metadata.Edm;
using System.Diagnostics;
using System.Xml;
/// <summary>
/// Represents an Key element in an EntityType element.
/// </summary>
internal sealed class EntityKeyElement : SchemaElement
{
private List<PropertyRefElement> _keyProperties;
/// <summary>
/// Constructs an EntityContainerAssociationSetEnd
/// </summary>
/// <param name="parentElement">Reference to the schema element.</param>
public EntityKeyElement( SchemaEntityType parentElement )
: base( parentElement )
{
}
public IList<PropertyRefElement> KeyProperties
{
get
{
if (_keyProperties == null)
{
_keyProperties = new List<PropertyRefElement>();
}
return _keyProperties;
}
}
protected override bool HandleAttribute(XmlReader reader)
{
return false;
}
protected override bool HandleElement(XmlReader reader)
{
if (base.HandleElement(reader))
{
return true;
}
else if (CanHandleElement(reader, XmlConstants.PropertyRef))
{
HandlePropertyRefElement(reader);
return true;
}
return false;
}
/// <summary>
///
/// </summary>
/// <param name="reader"></param>
private void HandlePropertyRefElement(XmlReader reader)
{
PropertyRefElement property = new PropertyRefElement((SchemaEntityType)ParentElement);
property.Parse(reader);
this.KeyProperties.Add(property);
}
/// <summary>
/// Used during the resolve phase to resolve the type name to the object that represents that type
/// </summary>
internal override void ResolveTopLevelNames()
{
Debug.Assert(_keyProperties != null, "xsd should have verified that there should be atleast one property ref element");
foreach (PropertyRefElement property in _keyProperties)
{
if (!property.ResolveNames((SchemaEntityType)this.ParentElement))
{
AddError(ErrorCode.InvalidKey, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.InvalidKeyNoProperty(this.ParentElement.FQName, property.Name));
}
}
}
/// <summary>
/// Validate all the key properties
/// </summary>
internal override void Validate()
{
Debug.Assert(_keyProperties != null, "xsd should have verified that there should be atleast one property ref element");
Dictionary<string, PropertyRefElement> propertyLookUp = new Dictionary<string, PropertyRefElement>(StringComparer.Ordinal);
foreach (PropertyRefElement keyProperty in _keyProperties)
{
StructuredProperty property = keyProperty.Property;
Debug.Assert(property != null, "This should never be null, since if we were not able to resolve, we should have never reached to this point");
if (propertyLookUp.ContainsKey(property.Name))
{
AddError(ErrorCode.DuplicatePropertySpecifiedInEntityKey, EdmSchemaErrorSeverity.Error,
System.Data.Entity.Strings.DuplicatePropertyNameSpecifiedInEntityKey(this.ParentElement.FQName, property.Name));
continue;
}
propertyLookUp.Add(property.Name, keyProperty);
if (property.Nullable)
{
AddError(ErrorCode.InvalidKey, EdmSchemaErrorSeverity.Error,
System.Data.Entity.Strings.InvalidKeyNullablePart(property.Name, this.ParentElement.Name));
}
// currently we only support key properties of scalar type
if (!(property.Type is ScalarType || property.Type is SchemaEnumType) || (property.CollectionKind != CollectionKind.None))
{
AddError(ErrorCode.EntityKeyMustBeScalar,
EdmSchemaErrorSeverity.Error,
System.Data.Entity.Strings.EntityKeyMustBeScalar(property.Name, this.ParentElement.Name));
continue;
}
// Enum properties are never backed by binary or spatial type so we can skip the checks here
if (!(property.Type is SchemaEnumType))
{
Debug.Assert(property.TypeUsage != null, "For scalar type, typeusage must be initialized");
PrimitiveType primitivePropertyType = (PrimitiveType)property.TypeUsage.EdmType;
if (Schema.DataModel == SchemaDataModelOption.EntityDataModel)
{
// Binary keys are only supported for V2.0 CSDL, Spatial keys are not supported.
if ((primitivePropertyType.PrimitiveTypeKind == PrimitiveTypeKind.Binary && Schema.SchemaVersion < XmlConstants.EdmVersionForV2) ||
Helper.IsSpatialType(primitivePropertyType))
{
AddError(ErrorCode.EntityKeyTypeCurrentlyNotSupported,
EdmSchemaErrorSeverity.Error,
Strings.EntityKeyTypeCurrentlyNotSupported(property.Name, this.ParentElement.FQName, primitivePropertyType.PrimitiveTypeKind));
}
}
else
{
Debug.Assert(SchemaDataModelOption.ProviderDataModel == Schema.DataModel, "Invalid DataModel encountered");
// Binary keys are only supported for V2.0 SSDL, Spatial keys are not supported.
if ((primitivePropertyType.PrimitiveTypeKind == PrimitiveTypeKind.Binary && Schema.SchemaVersion < XmlConstants.StoreVersionForV2) ||
Helper.IsSpatialType(primitivePropertyType))
{
AddError(ErrorCode.EntityKeyTypeCurrentlyNotSupported,
EdmSchemaErrorSeverity.Error,
Strings.EntityKeyTypeCurrentlyNotSupportedInSSDL(property.Name, this.ParentElement.FQName,
property.TypeUsage.EdmType.Name, property.TypeUsage.EdmType.BaseType.FullName, primitivePropertyType.PrimitiveTypeKind));
}
}
}
}
}
}
}

View File

@ -0,0 +1,392 @@
//---------------------------------------------------------------------
// <copyright file="ErrorCode.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//
// @owner jeffreed
// @backupOwner anpete
//---------------------------------------------------------------------
namespace System.Data.EntityModel.SchemaObjectModel
{
// This file contains an enum for the errors generated by Metadata Loading (SOM)
//
// There is almost a one-to-one correspondence between these error codes
// and the resource strings - so if you need more insight into what the
// error code means, please see the code that uses the particular enum
// AND the corresponding resource string
//
// error numbers end up being hard coded in test cases; they can be removed, but should not be changed.
// reusing error numbers is probably OK, but not recommended.
//
// The acceptable range for this enum is
// 0000 - 0999
//
// The Range 10,000-15,000 is reserved for tools
//
/// <summary>
/// Summary description for ErrorCode.
/// </summary>
internal enum ErrorCode
{
/// <summary></summary>
InvalidErrorCodeValue = 0,
// unused 1,
/// <summary></summary>
SecurityError = 2,
// unused 3,
/// <summary></summary>
IOException = 4,
/// <summary></summary>
XmlError = 5,
/// <summary></summary>
TooManyErrors = 6,
/// <summary></summary>
MalformedXml = 7,
/// <summary></summary>
UnexpectedXmlNodeType = 8,
/// <summary></summary>
UnexpectedXmlAttribute = 9,
/// <summary></summary>
UnexpectedXmlElement = 10,
/// <summary></summary>
TextNotAllowed = 11,
/// <summary></summary>
EmptyFile = 12,
/// <summary></summary>
XsdError = 13,
/// <summary></summary>
InvalidAlias = 14,
// unused 15,
/// <summary></summary>
IntegerExpected = 16,
/// <summary></summary>
InvalidName = 17,
// unused 18,
/// <summary></summary>
AlreadyDefined = 19,
/// <summary></summary>
ElementNotInSchema = 20,
// unused 21,
/// <summary></summary>
InvalidBaseType = 22,
/// <summary></summary>
NoConcreteDescendants = 23,
/// <summary></summary>
CycleInTypeHierarchy = 24,
/// <summary></summary>
InvalidVersionNumber = 25,
/// <summary></summary>
InvalidSize = 26,
/// <summary></summary>
InvalidBoolean = 27,
// unused 28,
/// <summary></summary>
BadType = 29,
// unused 30,
// unused 31,
/// <summary></summary>
InvalidVersioningClass = 32,
/// <summary></summary>
InvalidVersionIntroduced = 33,
/// <summary></summary>
BadNamespace = 34,
// unused 35,
// unused 36,
// unused 37,
/// <summary></summary>
UnresolvedReferenceSchema = 38,
// unused 39,
/// <summary></summary>
NotInNamespace = 40,
/// <summary></summary>
NotUnnestedType = 41,
/// <summary></summary>
BadProperty = 42,
/// <summary></summary>
UndefinedProperty = 43,
/// <summary></summary>
InvalidPropertyType = 44,
/// <summary></summary>
InvalidAsNestedType = 45,
/// <summary></summary>
InvalidChangeUnit = 46,
/// <summary></summary>
UnauthorizedAccessException = 47,
// unused 48,
// unused 49,
/// <summary>Namespace attribute must be specified.</summary>
MissingNamespaceAttribute = 50,
/// <summary> Precision out of range </summary>
PrecisionOutOfRange = 51,
/// <summary> Scale out of range </summary>
ScaleOutOfRange = 52,
/// <summary></summary>
DefaultNotAllowed = 53,
/// <summary></summary>
InvalidDefault = 54,
/// <summary>One of the required facets is missing</summary>
RequiredFacetMissing = 55,
/// <summary></summary>
BadImageFormatException = 56,
/// <summary></summary>
MissingSchemaXml = 57,
/// <summary></summary>
BadPrecisionAndScale = 58,
/// <summary></summary>
InvalidChangeUnitUsage = 59,
/// <summary></summary>
NameTooLong = 60,
/// <summary></summary>
CircularlyDefinedType = 61,
/// <summary></summary>
InvalidAssociation = 62,
/// <summary>
/// The facet isn't allow by the property type.
/// </summary>
FacetNotAllowedByType = 63,
/// <summary>
/// This facet value is constant and is specified in the schema
/// </summary>
ConstantFacetSpecifiedInSchema = 64,
// unused 65,
// unused 66,
// unused 67,
// unused 68,
// unused 69,
// unused 70,
// unused 71,
// unused 72,
// unused 73,
/// <summary></summary>
BadNavigationProperty = 74,
/// <summary></summary>
InvalidKey = 75,
// unused 76,
// unused 77,
// unused 78,
// unused 79,
// unused 80,
// unused 81,
// unused 82,
// unused 83,
// unused 84,
// unused 85,
// unused 86,
// unused 87,
// unused 88,
// unused 89,
// unused 90,
// unused 91,
/// <summary>Multiplicity value was malformed</summary>
InvalidMultiplicity = 92,
// unused 93,
// unused 94,
// unused 95,
/// <summary>The value for the Action attribute is invalid or not allowed in the current context</summary>
InvalidAction = 96,
/// <summary>An error occured processing the On&lt;Operation&gt; elements</summary>
InvalidOperation = 97,
// unused 98,
/// <summary>Ends were given for the Property element of a EntityContainer that is not a RelationshipSet</summary>
InvalidContainerTypeForEnd = 99,
/// <summary>The extent name used in the EntittyContainerType End does not match the name of any of the EntityContainerProperties in the containing EntityContainer</summary>
InvalidEndEntitySet = 100,
/// <summary>An end element was not given, and cannot be inferred because too many EntityContainerEntitySet elements that are good possibilities.</summary>
AmbiguousEntityContainerEnd = 101,
/// <summary>An end element was not given, and cannot be infered because there is no EntityContainerEntitySets that are the correct type to be used as an EntitySet.</summary>
MissingExtentEntityContainerEnd = 102,
// unused 103,
// unused 104,
// unused 105,
/// <summary>Not a valid parameter direction for the parameter in a function</summary>
BadParameterDirection = 106,
/// <summary>Unable to infer an optional schema part, to resolve this, be more explicit</summary>
FailedInference = 107,
// unused = 108,
/// <summary> Invalid facet attribute(s) specified in provider manifest</summary>
InvalidFacetInProviderManifest = 109,
/// <summary> Invalid role value in the relationship constraint</summary>
InvalidRoleInRelationshipConstraint = 110,
/// <summary> Invalid Property in relationship constraint</summary>
InvalidPropertyInRelationshipConstraint = 111,
/// <summary> Type mismatch between ToProperty and FromProperty in the relationship constraint</summary>
TypeMismatchRelationshipConstaint = 112,
/// <summary> Invalid multiplicty in FromRole in the relationship constraint</summary>
InvalidMultiplicityInRoleInRelationshipConstraint = 113,
/// <summary> The number of properties in the FromProperty and ToProperty in the relationship constraint must be identical</summary>
MismatchNumberOfPropertiesInRelationshipConstraint = 114,
/// <summary> No Properties defined in either FromProperty or ToProperty in the relationship constraint</summary>
MissingPropertyInRelationshipConstraint = 115,
/// <summary> Missing constraint in relationship type in ssdl</summary>
MissingConstraintOnRelationshipType = 116,
// unused 117,
// unused 118,
/// <summary> Same role referred in the ToRole and FromRole of a referential constraint </summary>
SameRoleReferredInReferentialConstraint = 119,
/// <summary> Invalid value for attribute ParameterTypeSemantics </summary>
InvalidValueForParameterTypeSemantics = 120,
/// <summary> Invalid type used for a Relationship End Type</summary>
InvalidRelationshipEndType = 121,
/// <summary> Invalid PrimitiveTypeKind</summary>
InvalidPrimitiveTypeKind = 122,
// unused 123,
/// <summary> Invalid TypeConversion DestinationType</summary>
InvalidTypeConversionDestinationType = 124,
/// <summary>Expected a integer value between 0 - 255</summary>
ByteValueExpected = 125,
/// <summary> Invalid Type specified in function</summary>
FunctionWithNonPrimitiveTypeNotSupported = 126,
/// <summary> Precision must not be greater than 28 </summary>
PrecisionMoreThanAllowedMax = 127,
/// <summary> Properties that are part of entity key must be of scalar type</summary>
EntityKeyMustBeScalar = 128,
/// <summary> Binary and spatial type properties which are part of entity key are currently not supported </summary>
EntityKeyTypeCurrentlyNotSupported = 129,
/// <summary>The primitive type kind does not have a prefered mapping</summary>
NoPreferredMappingForPrimitiveTypeKind = 130,
/// <summary>More than one PreferredMapping for a PrimitiveTypeKind</summary>
TooManyPreferredMappingsForPrimitiveTypeKind = 131,
/// <summary>End with * multiplicity cannot have operations specified</summary>
EndWithManyMultiplicityCannotHaveOperationsSpecified = 132,
/// <summary>EntitySet type has no keys</summary>
EntitySetTypeHasNoKeys = 133,
/// <summary>InvalidNumberOfParametersForAggregateFunction</summary>
InvalidNumberOfParametersForAggregateFunction = 134,
/// <summary>InvalidParameterTypeForAggregateFunction</summary>
InvalidParameterTypeForAggregateFunction = 135,
/// <summary>Composable functions and function imports must declare a return type.</summary>
ComposableFunctionOrFunctionImportWithoutReturnType = 136,
/// <summary>Non-composable functions must not declare a return type.</summary>
NonComposableFunctionWithReturnType = 137,
/// <summary>Non-composable functions do not permit the aggregate, niladic, or built-in attributes.</summary>
NonComposableFunctionAttributesNotValid = 138,
/// <summary>Composable functions can not include command text attribute.</summary>
ComposableFunctionWithCommandText = 139,
/// <summary>Functions should not declare both a store name and command text (only one or the other
/// can be used).</summary>
FunctionDeclaresCommandTextAndStoreFunctionName = 140,
/// <summary>SystemNamespace</summary>
SystemNamespace = 141,
/// <summary>Empty DefiningQuery text</summary>
EmptyDefiningQuery = 142,
/// <summary>Schema, Table and DefiningQuery are all specified, and are mutualy exlusive</summary>
TableAndSchemaAreMutuallyExclusiveWithDefiningQuery = 143,
// unused 144,
/// <summary>Conurency can't change for any sub types of an EntitySet type.</summary>
ConcurrencyRedefinedOnSubTypeOfEntitySetType = 145,
/// <summary>Function import return type must be either empty, a collection of entities, or a singleton scalar.</summary>
FunctionImportUnsupportedReturnType = 146,
/// <summary>Function import specifies a non-existent entity set.</summary>
FunctionImportUnknownEntitySet = 147,
/// <summary>Function import specifies entity type return but no entity set.</summary>
FunctionImportReturnsEntitiesButDoesNotSpecifyEntitySet = 148,
/// <summary>Function import specifies entity type that does not derive from element type of entity set.</summary>
FunctionImportEntityTypeDoesNotMatchEntitySet = 149,
/// <summary>Function import specifies a binding to an entity set but does not return entities.</summary>
FunctionImportSpecifiesEntitySetButDoesNotReturnEntityType = 150,
/// <summary>InternalError</summary>
InternalError = 152,
/// <summary>Same Entity Set Taking part in the same role of the relationship set in two different relationship sets</summary>
SimilarRelationshipEnd = 153,
/// <summary> Entity key refers to the same property twice</summary>
DuplicatePropertySpecifiedInEntityKey = 154,
/// <summary> Function declares a ReturnType attribute and element</summary>
AmbiguousFunctionReturnType = 156,
/// <summary> Nullable Complex Type not supported in Edm V1</summary>
NullableComplexType = 157,
/// <summary> Only Complex Collections supported in Edm V1.1</summary>
NonComplexCollections = 158,
/// <summary>No Key defined on Entity Type </summary>
KeyMissingOnEntityType = 159,
/// <summary> Invalid namespace specified in using element</summary>
InvalidNamespaceInUsing = 160,
/// <summary> Need not specify system namespace in using </summary>
NeedNotUseSystemNamespaceInUsing = 161,
/// <summary> Cannot use a reserved/system namespace as alias </summary>
CannotUseSystemNamespaceAsAlias = 162,
/// <summary> Invalid qualification specified for type </summary>
InvalidNamespaceName = 163,
/// <summary> Invalid Entity Container Name in extends attribute </summary>
InvalidEntityContainerNameInExtends = 164,
// unused 165,
/// <summary> Must specify namespace or alias of the schema in which this type is defined </summary>
InvalidNamespaceOrAliasSpecified = 166,
/// <summary> Entity Container cannot extend itself </summary>
EntityContainerCannotExtendItself = 167,
/// <summary> Failed to retrieve provider manifest </summary>
FailedToRetrieveProviderManifest = 168,
/// <summary> Mismatched Provider Manifest token values in SSDL artifacts </summary>
ProviderManifestTokenMismatch = 169,
/// <summary> Missing Provider Manifest token value in SSDL artifact(s) </summary>
ProviderManifestTokenNotFound = 170,
/// <summary>Empty CommandText element</summary>
EmptyCommandText = 171,
/// <summary> Inconsistent Provider values in SSDL artifacts </summary>
InconsistentProvider = 172,
/// <summary> Inconsistent Provider Manifest token values in SSDL artifacts </summary>
InconsistentProviderManifestToken = 173,
/// <summary> Duplicated Function overloads </summary>
DuplicatedFunctionoverloads = 174,
/// <summary>InvalidProvider</summary>
InvalidProvider = 175,
/// <summary>FunctionWithNonEdmTypeNotSupported</summary>
FunctionWithNonEdmTypeNotSupported = 176,
/// <summary>ComplexTypeAsReturnTypeAndDefinedEntitySet</summary>
ComplexTypeAsReturnTypeAndDefinedEntitySet = 177,
/// <summary>ComplexTypeAsReturnTypeAndDefinedEntitySet</summary>
ComplexTypeAsReturnTypeAndNestedComplexProperty = 178,
// unused = 179,
/// <summary>A function import can be either composable or side-effecting, but not both.</summary>
FunctionImportComposableAndSideEffectingNotAllowed = 180,
/// <summary>A function import can specify an entity set or an entity set path, but not both.</summary>
FunctionImportEntitySetAndEntitySetPathDeclared = 181,
/// <summary>In model functions facet attribute is allowed only on ScalarTypes</summary>
FacetOnNonScalarType = 182,
/// <summary>Captures several conditions where facets are placed on element where it should not exist.</summary>
IncorrectlyPlacedFacet = 183,
/// <summary>Return type has not been declared</summary>
ReturnTypeNotDeclared = 184,
TypeNotDeclared = 185,
RowTypeWithoutProperty = 186,
ReturnTypeDeclaredAsAttributeAndElement = 187,
TypeDeclaredAsAttributeAndElement = 188,
ReferenceToNonEntityType = 189,
/// <summary>Collection and reference type parameters are not allowed in function imports.</summary>
FunctionImportCollectionAndRefParametersNotAllowed = 190,
IncompatibleSchemaVersion = 191,
/// <summary> The structural annotation cannot use codegen namespaces </summary>
NoCodeGenNamespaceInStructuralAnnotation = 192,
/// <summary> Function and type cannot have the same fully qualified name</summary>
AmbiguousFunctionAndType = 193,
/// <summary> Cannot load different version of schema in the same ItemCollection</summary>
CannotLoadDifferentVersionOfSchemaInTheSameItemCollection = 194,
/// <summary> Expected bool value</summary>
BoolValueExpected = 195,
/// <summary> End without Multiplicity specified</summary>
EndWithoutMultiplicity = 196,
/// <summary>In SSDL, if composable function returns a collection of rows (TVF), all row properties must be of scalar types.</summary>
TVFReturnTypeRowHasNonScalarProperty = 197,
// FunctionUnknownEntityContainer = 198,
// FunctionEntityContainerMustBeSpecified = 199,
// FunctionUnknownEntitySet = 200,
/// <summary>Only nullable parameters are supported in function imports.</summary>
FunctionImportNonNullableParametersNotAllowed = 201,
/// <summary>Defining expression and entity set can not be specified at the same time.</summary>
FunctionWithDefiningExpressionAndEntitySetNotAllowed = 202,
/// <summary>Function specifies return type that does not derive from element type of entity set.</summary>
FunctionEntityTypeScopeDoesNotMatchReturnType = 203,
/// <summary>The specified type cannot be used as the underlying type of Enum type.</summary>
InvalidEnumUnderlyingType = 204,
/// <summary>Duplicate enumeration member.</summary>
DuplicateEnumMember = 205,
/// <summary>The calculated value for an enum member is ouf of Int64 range.</summary>
CalculatedEnumValueOutOfRange = 206,
/// <summary>The enumeration value for an enum member is out of its underlying type range.</summary>
EnumMemberValueOutOfItsUnderylingTypeRange = 207,
/// <summary>The Srid value is out of range.</summary>
InvalidSystemReferenceId = 208,
/// <summary>A CSDL spatial type in a file without the UseSpatialUnionType annotation</summary>
UnexpectedSpatialType = 209,
}
}

View File

@ -0,0 +1,158 @@
//---------------------------------------------------------------------
// <copyright file="FacetDescriptionElement.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.Metadata.Edm;
using System.Xml;
using System.Diagnostics;
namespace System.Data.EntityModel.SchemaObjectModel
{
internal abstract class FacetDescriptionElement : SchemaElement
{
int? _minValue;
int? _maxValue;
object _defaultValue;
bool _isConstant;
// won't be populated till you call CreateAndValidate
FacetDescription _facetDescription;
public FacetDescriptionElement(TypeElement type, string name)
: base(type, name)
{
}
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.MinimumAttribute))
{
HandleMinimumAttribute(reader);
return true;
}
else if (CanHandleAttribute(reader, XmlConstants.MaximumAttribute))
{
HandleMaximumAttribute(reader);
return true;
}
else if (CanHandleAttribute(reader, XmlConstants.DefaultValueAttribute))
{
HandleDefaultAttribute(reader);
return true;
}
else if (CanHandleAttribute(reader, XmlConstants.ConstantAttribute))
{
HandleConstantAttribute(reader);
return true;
}
return false;
}
/////////////////////////////////////////////////////////////////////
// Attribute Handlers
/// <summary>
/// Handler for the Minimum attribute
/// </summary>
/// <param name="reader">xml reader currently positioned at Minimum attribute</param>
protected void HandleMinimumAttribute(XmlReader reader)
{
int value = -1;
if (HandleIntAttribute(reader, ref value))
{
_minValue = value;
}
}
/// <summary>
/// Handler for the Maximum attribute
/// </summary>
/// <param name="reader">xml reader currently positioned at Maximum attribute</param>
protected void HandleMaximumAttribute(XmlReader reader)
{
int value = -1;
if (HandleIntAttribute(reader, ref value))
{
_maxValue = value;
}
}
/// <summary>
/// Handler for the Default attribute
/// </summary>
/// <param name="reader">xml reader currently positioned at Default attribute</param>
protected abstract void HandleDefaultAttribute(XmlReader reader);
/// <summary>
/// Handler for the Constant attribute
/// </summary>
/// <param name="reader">xml reader currently positioned at Constant attribute</param>
protected void HandleConstantAttribute(XmlReader reader)
{
bool value = false;
if (HandleBoolAttribute(reader, ref value))
{
_isConstant = value;
}
}
public abstract EdmType FacetType{ get; }
public int? MinValue
{
get { return _minValue; }
}
public int? MaxValue
{
get { return _maxValue; }
}
public object DefaultValue
{
get { return _defaultValue; }
set { _defaultValue = value; }
}
public FacetDescription FacetDescription
{
get
{
Debug.Assert(_facetDescription != null, "Did you forget to call CreateAndValidate first?");
return _facetDescription;
}
}
internal void CreateAndValidateFacetDescription(string declaringTypeName)
{
_facetDescription = new FacetDescription(Name, FacetType, MinValue, MaxValue, DefaultValue, _isConstant, declaringTypeName);
}
}
}

View File

@ -0,0 +1,142 @@
//---------------------------------------------------------------------
// <copyright file="FacetEnabledSchemaElement.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Metadata.Edm;
using System.Diagnostics;
using System.Xml;
namespace System.Data.EntityModel.SchemaObjectModel
{
internal abstract class FacetEnabledSchemaElement : SchemaElement
{
protected SchemaType _type = null;
protected string _unresolvedType = null;
protected TypeUsageBuilder _typeUsageBuilder;
#region Properties
internal new Function ParentElement
{
get
{
return base.ParentElement as Function;
}
}
internal SchemaType Type
{
get
{
return _type;
}
}
internal virtual TypeUsage TypeUsage
{
get
{
return _typeUsageBuilder.TypeUsage;
}
}
internal TypeUsageBuilder TypeUsageBuilder
{
get
{
return _typeUsageBuilder;
}
}
internal bool HasUserDefinedFacets
{
get
{
return _typeUsageBuilder.HasUserDefinedFacets;
}
}
internal string UnresolvedType
{
get
{
return _unresolvedType;
}
set
{
_unresolvedType = value;
}
}
#endregion
#region Methods
/// <summary>
///
/// </summary>
/// <param name="parentElement"></param>
internal FacetEnabledSchemaElement(Function parentElement)
: base(parentElement)
{
}
internal FacetEnabledSchemaElement(SchemaElement parentElement)
: base(parentElement)
{
}
internal override void ResolveTopLevelNames()
{
base.ResolveTopLevelNames();
Debug.Assert(this.Type == null, "This must be resolved exactly once");
if (Schema.ResolveTypeName(this, UnresolvedType, out _type))
{
if (Schema.DataModel == SchemaDataModelOption.ProviderManifestModel && _typeUsageBuilder.HasUserDefinedFacets)
{
bool isInProviderManifest = Schema.DataModel == SchemaDataModelOption.ProviderManifestModel;
_typeUsageBuilder.ValidateAndSetTypeUsage((ScalarType)_type, !isInProviderManifest);
}
}
}
internal void ValidateAndSetTypeUsage(ScalarType scalar)
{
_typeUsageBuilder.ValidateAndSetTypeUsage(scalar, false);
}
internal void ValidateAndSetTypeUsage(EdmType edmType)
{
_typeUsageBuilder.ValidateAndSetTypeUsage(edmType, false);
}
#endregion
protected override bool HandleAttribute(XmlReader reader)
{
if (base.HandleAttribute(reader))
{
return true;
}
else if (_typeUsageBuilder.HandleAttribute(reader))
{
return true;
}
return false;
}
}
}

View File

@ -0,0 +1,117 @@
//---------------------------------------------------------------------
// <copyright file="FilteredSchemaElementLookUpTable.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
namespace System.Data.EntityModel.SchemaObjectModel
{
using System.Collections;
using System.Collections.Generic;
using System.Data;
/// <summary>
/// Summary description for FilteredSchemaTypes.
/// </summary>
internal sealed class FilteredSchemaElementLookUpTable<T,S> : IEnumerable<T>, ISchemaElementLookUpTable<T>
where T : S
where S : SchemaElement
{
#region Instance Fields
private SchemaElementLookUpTable<S> _lookUpTable = null;
#endregion
#region Public Methods
/// <summary>
///
/// </summary>
/// <param name="lookUpTable"></param>
public FilteredSchemaElementLookUpTable(SchemaElementLookUpTable<S> lookUpTable)
{
_lookUpTable = lookUpTable;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public IEnumerator<T> GetEnumerator()
{
return _lookUpTable.GetFilteredEnumerator<T>();
}
/// <summary>
///
/// </summary>
/// <returns></returns>
IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return _lookUpTable.GetFilteredEnumerator<T>();
}
/// <summary>
///
/// </summary>
public int Count
{
get
{
int count = 0;
foreach ( SchemaElement element in _lookUpTable )
{
if ( element is T )
{
++count;
}
}
return count;
}
}
/// <summary>
///
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public bool ContainsKey(string key)
{
if ( !_lookUpTable.ContainsKey(key) )
return false;
return _lookUpTable[key] as T != null;
}
/// <summary>
///
/// </summary>
public T this[string key]
{
get
{
S element = _lookUpTable[key];
if ( element == null )
{
return null;
}
T elementAsT = element as T;
if ( elementAsT != null )
{
return elementAsT;
}
throw EntityUtil.InvalidOperation(System.Data.Entity.Strings.UnexpectedTypeInCollection(element.GetType(),key));
}
}
/// <summary>
///
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public T LookUpEquivalentKey(string key)
{
return _lookUpTable.LookUpEquivalentKey(key) as T;
}
#endregion
}
}

Some files were not shown because too many files have changed in this diff Show More