private void HandleEntityTypeElement(XmlReader reader) { SchemaEntityType schemaEntityType = new SchemaEntityType(this); schemaEntityType.Parse(reader); this.TryAddType((SchemaType)schemaEntityType, true); }
internal bool ResolveNames(SchemaEntityType entityType) { if (string.IsNullOrEmpty(this.Name)) { return(true); } this._property = entityType.FindProperty(this.Name); return(this._property != null); }
internal override void Validate() { base.Validate(); if (this._fromEnd.Type != this.ParentElement) { this.AddError(ErrorCode.BadNavigationProperty, EdmSchemaErrorSeverity.Error, (object)Strings.BadNavigationPropertyBadFromRoleType((object)this.Name, (object)this._fromEnd.Type.FQName, (object)this._fromEnd.Name, (object)this._relationship.FQName, (object)this.ParentElement.FQName)); } SchemaEntityType type = this._toEnd.Type; }
// <summary> // Handler for the EntityType element // </summary> // <param name="reader"> xml reader currently positioned at EntityType element </param> private void HandleEntityTypeElement(XmlReader reader) { DebugCheck.NotNull(reader); var itemType = new SchemaEntityType(this); itemType.Parse(reader); TryAddType(itemType, true /*doNotAddErrorForEmptyName*/); }
private static bool TypeDefinesNewConcurrencyProperties(SchemaEntityType itemType) { foreach (StructuredProperty property in itemType.Properties) { if (property.Type is ScalarType && MetadataHelper.GetConcurrencyMode(property.TypeUsage) != ConcurrencyMode.None) { return(true); } } return(false); }
internal override void ResolveTopLevelNames() { IRelationship parentElement = (IRelationship)this.ParentElement.ParentElement; if (!parentElement.TryGetEnd(this.Name, out this._end)) { this.AddError(ErrorCode.InvalidRoleInRelationshipConstraint, EdmSchemaErrorSeverity.Error, (object)Strings.InvalidEndRoleInRelationshipConstraint((object)this.Name, (object)parentElement.Name)); } else { SchemaEntityType type = this._end.Type; } }
/// <summary> /// Since this method can be used in different context, this method does not add any errors /// Please make sure that the caller of this methods handles the error case and add errors /// appropriately /// </summary> /// <param name="entityType"> </param> /// <returns> </returns> internal bool ResolveNames(SchemaEntityType entityType) { if (string.IsNullOrEmpty(Name)) { // Don't flag this error. This must already must have flaged as error, while handling name attribute return true; } // Make sure there is a property by this name _property = entityType.FindProperty(Name); return (_property != null); }
/// <summary> /// Since this method can be used in different context, this method does not add any errors /// Please make sure that the caller of this methods handles the error case and add errors /// appropriately /// </summary> internal bool ResolveNames(SchemaEntityType entityType) { if (string.IsNullOrEmpty(Name)) { // Don't flag this error. This must already must have flaged as error, while handling name attribute return(true); } // Make sure there is a property by this name _property = entityType.FindProperty(Name); return(_property != null); }
// <summary> // Resolves the given property names to the property in the item // Also checks whether the properties form the key for the given type and whether all the properties are nullable or not // </summary> private static void IsKeyProperty( ReferentialConstraintRoleElement roleElement, SchemaEntityType itemType, out bool isKeyProperty, out bool areAllPropertiesNullable, out bool isAnyPropertyNullable, out bool isSubsetOfKeyProperties) { isKeyProperty = true; areAllPropertiesNullable = true; isAnyPropertyNullable = false; isSubsetOfKeyProperties = true; if (itemType.KeyProperties.Count != roleElement.RoleProperties.Count) { isKeyProperty = false; } // Checking that ToProperties must be the key properties in the entity type referred by the ToRole for (var i = 0; i < roleElement.RoleProperties.Count; i++) { // Once we find that the properties in the constraint are not a subset of the // Key, one need not search for it every time if (isSubsetOfKeyProperties) { var foundKeyProperty = false; // All properties that are defined in ToProperties must be the key property on the entity type for (var j = 0; j < itemType.KeyProperties.Count; j++) { if (itemType.KeyProperties[j].Property == roleElement.RoleProperties[i].Property) { foundKeyProperty = true; break; } } if (!foundKeyProperty) { isKeyProperty = false; isSubsetOfKeyProperties = false; } } areAllPropertiesNullable &= roleElement.RoleProperties[i].Property.Nullable; isAnyPropertyNullable |= roleElement.RoleProperties[i].Property.Nullable; } }
private void ValidateFunctionImportReturnType( SchemaElement owner, SchemaType returnType, EntityContainerEntitySet entitySet, bool entitySetPathDefined) { SchemaEntityType schemaEntityType = returnType as SchemaEntityType; if (entitySet != null && entitySetPathDefined) { owner.AddError(ErrorCode.FunctionImportEntitySetAndEntitySetPathDeclared, EdmSchemaErrorSeverity.Error, (object)Strings.FunctionImportEntitySetAndEntitySetPathDeclared((object)this.FQName)); } if (schemaEntityType != null) { if (entitySet == null) { owner.AddError(ErrorCode.FunctionImportReturnsEntitiesButDoesNotSpecifyEntitySet, EdmSchemaErrorSeverity.Error, (object)Strings.FunctionImportReturnEntitiesButDoesNotSpecifyEntitySet((object)this.FQName)); } else { if (entitySet.EntityType == null || schemaEntityType.IsOfType((StructuredType)entitySet.EntityType)) { return; } owner.AddError(ErrorCode.FunctionImportEntityTypeDoesNotMatchEntitySet, EdmSchemaErrorSeverity.Error, (object)Strings.FunctionImportEntityTypeDoesNotMatchEntitySet((object)this.FQName, (object)entitySet.EntityType.FQName, (object)entitySet.Name)); } } else { SchemaComplexType schemaComplexType = returnType as SchemaComplexType; if (schemaComplexType != null) { if (entitySet == null && !entitySetPathDefined) { return; } owner.AddError(ErrorCode.ComplexTypeAsReturnTypeAndDefinedEntitySet, EdmSchemaErrorSeverity.Error, owner.LineNumber, owner.LinePosition, (object)Strings.ComplexTypeAsReturnTypeAndDefinedEntitySet((object)this.FQName, (object)schemaComplexType.Name)); } else { if (entitySet == null && !entitySetPathDefined) { return; } owner.AddError(ErrorCode.FunctionImportSpecifiesEntitySetButDoesNotReturnEntityType, EdmSchemaErrorSeverity.Error, (object)Strings.FunctionImportSpecifiesEntitySetButNotEntityType((object)this.FQName)); } } }
internal override void ResolveTopLevelNames() { base.ResolveTopLevelNames(); if (this._entityType != null) { return; } SchemaType type = (SchemaType)null; if (!this.Schema.ResolveTypeName((SchemaElement)this, this._unresolvedEntityTypeName, out type)) { return; } this._entityType = type as SchemaEntityType; if (this._entityType != null) { return; } this.AddError(ErrorCode.InvalidPropertyType, EdmSchemaErrorSeverity.Error, (object)Strings.InvalidEntitySetType((object)this._unresolvedEntityTypeName)); }
private static bool TypeIsSubTypeOf( SchemaEntityType itemType, Dictionary <SchemaEntityType, EntityContainerEntitySet> baseEntitySetTypes, out EntityContainerEntitySet set) { if (itemType.IsTypeHierarchyRoot) { set = (EntityContainerEntitySet)null; return(false); } for (SchemaEntityType baseType = itemType.BaseType as SchemaEntityType; baseType != null; baseType = baseType.BaseType as SchemaEntityType) { if (baseEntitySetTypes.ContainsKey(baseType)) { set = baseEntitySetTypes[baseType]; return(true); } } set = (EntityContainerEntitySet)null; return(false); }
private void ValidateOnlyBaseEntitySetTypeDefinesConcurrency() { Dictionary <SchemaEntityType, EntityContainerEntitySet> baseEntitySetTypes = new Dictionary <SchemaEntityType, EntityContainerEntitySet>(); foreach (SchemaElement member in this.Members) { EntityContainerEntitySet containerEntitySet = member as EntityContainerEntitySet; if (containerEntitySet != null && !baseEntitySetTypes.ContainsKey(containerEntitySet.EntityType)) { baseEntitySetTypes.Add(containerEntitySet.EntityType, containerEntitySet); } } foreach (SchemaType schemaType in this.Schema.SchemaTypes) { SchemaEntityType itemType = schemaType as SchemaEntityType; EntityContainerEntitySet set; if (itemType != null && EntityContainer.TypeIsSubTypeOf(itemType, baseEntitySetTypes, out set) && EntityContainer.TypeDefinesNewConcurrencyProperties(itemType)) { this.AddError(ErrorCode.ConcurrencyRedefinedOnSubTypeOfEntitySetType, EdmSchemaErrorSeverity.Error, (object)Strings.ConcurrencyRedefinedOnSubTypeOfEntitySetType((object)itemType.FQName, (object)set.EntityType.FQName, (object)set.FQName)); } } }
private static void IsKeyProperty( ReferentialConstraintRoleElement roleElement, SchemaEntityType itemType, out bool isKeyProperty, out bool areAllPropertiesNullable, out bool isAnyPropertyNullable, out bool isSubsetOfKeyProperties) { isKeyProperty = true; areAllPropertiesNullable = true; isAnyPropertyNullable = false; isSubsetOfKeyProperties = true; if (itemType.KeyProperties.Count != roleElement.RoleProperties.Count) { isKeyProperty = false; } for (int index1 = 0; index1 < roleElement.RoleProperties.Count; ++index1) { if (isSubsetOfKeyProperties) { bool flag = false; for (int index2 = 0; index2 < itemType.KeyProperties.Count; ++index2) { if (itemType.KeyProperties[index2].Property == roleElement.RoleProperties[index1].Property) { flag = true; break; } } if (!flag) { isKeyProperty = false; isSubsetOfKeyProperties = false; } } areAllPropertiesNullable &= roleElement.RoleProperties[index1].Property.Nullable; isAnyPropertyNullable |= roleElement.RoleProperties[index1].Property.Nullable; } }
// <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, Strings.InvalidEntitySetType(_unresolvedEntityTypeName)); return; } } }
private static bool TypeIsSubTypeOf( SchemaEntityType itemType, Dictionary <SchemaEntityType, EntityContainerEntitySet> baseEntitySetTypes, out EntityContainerEntitySet set) { if (itemType.IsTypeHierarchyRoot) { // can't be a sub type if we are a base type set = null; return(false); } // walk up the hierarchy looking for a base that is the base type of an entityset for (var baseType = itemType.BaseType as SchemaEntityType; baseType != null; baseType = baseType.BaseType as SchemaEntityType) { if (baseEntitySetTypes.ContainsKey(baseType)) { set = baseEntitySetTypes[baseType]; return(true); } } set = null; return(false); }
/// <summary> /// Resolves the given property names to the property in the item /// Also checks whether the properties form the key for the given type and whether all the properties are nullable or not /// </summary> /// <param name="roleElement"> </param> /// <param name="itemType"> </param> /// <param name="isKeyProperty"> </param> /// <param name="areAllPropertiesNullable"> </param> /// <param name="isSubsetOfKeyProperties"> </param> private static void IsKeyProperty( ReferentialConstraintRoleElement roleElement, SchemaEntityType itemType, out bool isKeyProperty, out bool areAllPropertiesNullable, out bool isAnyPropertyNullable, out bool isSubsetOfKeyProperties) { isKeyProperty = true; areAllPropertiesNullable = true; isAnyPropertyNullable = false; isSubsetOfKeyProperties = true; if (itemType.KeyProperties.Count != roleElement.RoleProperties.Count) { isKeyProperty = false; } // Checking that ToProperties must be the key properties in the entity type referred by the ToRole for (var i = 0; i < roleElement.RoleProperties.Count; i++) { // Once we find that the properties in the constraint are not a subset of the // Key, one need not search for it every time if (isSubsetOfKeyProperties) { var foundKeyProperty = false; // All properties that are defined in ToProperties must be the key property on the entity type for (var j = 0; j < itemType.KeyProperties.Count; j++) { if (itemType.KeyProperties[j].Property == roleElement.RoleProperties[i].Property) { foundKeyProperty = true; break; } } if (!foundKeyProperty) { isKeyProperty = false; isSubsetOfKeyProperties = false; } } areAllPropertiesNullable &= roleElement.RoleProperties[i].Property.Nullable; isAnyPropertyNullable |= roleElement.RoleProperties[i].Property.Nullable; } }
public NavigationProperty(SchemaEntityType parent) : base(parent) { }
/// <summary> /// Converts an entity type from SOM to metadata /// This method should only build the internally contained and vertical part of the EntityType (keys, properties, and base types) but not /// sideways parts (NavigationProperties) that go between types or we risk trying to access and EntityTypes keys, from the referential constraint, /// before the base type, which has the keys, is setup yet. /// </summary> /// <param name="element"> The SOM element to process </param> /// <param name="providerManifest"> The provider manifest to be used for conversion </param> /// <param name="convertedItemCache"> The item collection for currently existing metadata objects </param> /// <param name="newGlobalItems"> The new GlobalItem objects that are created as a result of this conversion </param> /// <returns> The entity type object resulting from the convert </returns> private static EntityType ConvertToEntityType( SchemaEntityType element, DbProviderManifest providerManifest, ConversionCache convertedItemCache, Dictionary<SchemaElement, GlobalItem> newGlobalItems) { string[] keyMembers = null; // Check if this type has keys if (element.DeclaredKeyProperties.Count != 0) { keyMembers = new string[element.DeclaredKeyProperties.Count]; for (var i = 0; i < keyMembers.Length; i++) { //Add the name of the key property to the list of //key properties keyMembers[i] = (element.DeclaredKeyProperties[i].Property.Name); } } var properties = new EdmProperty[element.Properties.Count]; var index = 0; foreach (var somProperty in element.Properties) { properties[index++] = ConvertToProperty( somProperty, providerManifest, convertedItemCache, newGlobalItems); } var entityType = new EntityType( element.Name, element.Namespace, GetDataSpace(providerManifest), keyMembers, properties); if (element.BaseType != null) { entityType.BaseType = (EdmType)(LoadSchemaElement( element.BaseType, providerManifest, convertedItemCache, newGlobalItems)); } // set the abstract and sealed type values for the entity type entityType.Abstract = element.IsAbstract; // Extract the optional Documentation if (element.Documentation != null) { entityType.Documentation = ConvertToDocumentation(element.Documentation); } AddOtherContent(element, entityType); newGlobalItems.Add(element, entityType); return entityType; }
public NavigationProperty(SchemaEntityType parent) : base((StructuredType)parent) { }
// <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, Strings.InvalidEntitySetType(_unresolvedEntityTypeName)); return; } } }
private static bool TypeIsSubTypeOf( SchemaEntityType itemType, Dictionary<SchemaEntityType, EntityContainerEntitySet> baseEntitySetTypes, out EntityContainerEntitySet set) { if (itemType.IsTypeHierarchyRoot) { // can't be a sub type if we are a base type set = null; return false; } // walk up the hierarchy looking for a base that is the base type of an entityset for (var baseType = itemType.BaseType as SchemaEntityType; baseType != null; baseType = baseType.BaseType as SchemaEntityType) { if (baseEntitySetTypes.ContainsKey(baseType)) { set = baseEntitySetTypes[baseType]; return true; } } set = null; return false; }
/// <summary> /// Constructs an EntityContainerAssociationSetEnd /// </summary> /// <param name="parentElement"> Reference to the schema element. </param> public EntityKeyElement(SchemaEntityType parentElement) : base(parentElement) { }
private static bool TypeDefinesNewConcurrencyProperties(SchemaEntityType itemType) { foreach (var property in itemType.Properties) { if (property.Type is ScalarType && MetadataHelper.GetConcurrencyMode(property.TypeUsage) != ConcurrencyMode.None) { return true; } } return false; }
private static void LoadEntityTypePhase2( SchemaEntityType element, DbProviderManifest providerManifest, ConversionCache convertedItemCache, Dictionary<SchemaElement, GlobalItem> newGlobalItems) { var entityType = (EntityType)newGlobalItems[element]; // Since Navigation properties are internal and not part of member collection, we // need to initialize the base class first before we start adding the navigation property // this will ensure that all the base navigation properties are initialized foreach (var somNavigationProperty in element.NavigationProperties) { entityType.AddMember( ConvertToNavigationProperty( entityType, somNavigationProperty, providerManifest, convertedItemCache, newGlobalItems)); } }
public EntityKeyElement(SchemaEntityType parentElement) : base((SchemaElement)parentElement, (IDbDependencyResolver)null) { }