/// <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>
        ///     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)
 {
 }
Пример #4
0
        // <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*/);
        }
        // <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;
                }
            }
        }
Пример #6
0
        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;
        }
Пример #7
0
        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)
 {
 }
Пример #9
0
        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));
            }
        }
Пример #10
0
        /// <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;
        }