public void LoadTypes(
     EdmItemCollection edmItemCollection,
     ObjectItemCollection objectItemCollection)
 {
     foreach (EdmType edmType in edmItemCollection.OfType <EdmType>().Where <EdmType>((Func <EdmType, bool>)(t =>
     {
         if (t.BuiltInTypeKind != BuiltInTypeKind.EntityType && t.BuiltInTypeKind != BuiltInTypeKind.EnumType)
         {
             return(t.BuiltInTypeKind == BuiltInTypeKind.ComplexType);
         }
         return(true);
     })))
     {
         Type clrType = edmType.GetClrType();
         if (clrType != (Type)null)
         {
             EdmType type = this._typeFactory.TryCreateType(clrType, edmType);
             if (type != null)
             {
                 this._typeFactory.CspaceToOspace.Add(edmType, type);
             }
         }
     }
     this._typeFactory.CreateRelationships(edmItemCollection);
     foreach (Action referenceResolution in this._typeFactory.ReferenceResolutions)
     {
         referenceResolution();
     }
     foreach (MetadataItem metadataItem in this._typeFactory.LoadedTypes.Values)
     {
         metadataItem.SetReadOnly();
     }
     objectItemCollection.AddLoadedTypes(this._typeFactory.LoadedTypes);
     objectItemCollection.OSpaceTypesLoaded = true;
 }
        public void LoadTypes(EdmItemCollection edmItemCollection, ObjectItemCollection objectItemCollection)
        {
            DebugCheck.NotNull(edmItemCollection);
            DebugCheck.NotNull(objectItemCollection);

            foreach (var cSpaceType in edmItemCollection.OfType<EdmType>().Where(
                t => t.BuiltInTypeKind == BuiltInTypeKind.EntityType
                     || t.BuiltInTypeKind == BuiltInTypeKind.EnumType
                     || t.BuiltInTypeKind == BuiltInTypeKind.ComplexType))
            {
                var clrType = cSpaceType.GetClrType();
                if (clrType != null)
                {
                    var oSpaceType = _typeFactory.TryCreateType(clrType, cSpaceType);
                    if (oSpaceType != null)
                    {
                        Debug.Assert(!_typeFactory.CspaceToOspace.ContainsKey(cSpaceType));
                        _typeFactory.CspaceToOspace.Add(cSpaceType, oSpaceType);
                    }
                }
                else
                {
                    Debug.Assert(!(cSpaceType is EntityType || cSpaceType is ComplexType || cSpaceType is EnumType));
                }
            }

            _typeFactory.CreateRelationships(edmItemCollection);

            foreach (var resolve in _typeFactory.ReferenceResolutions)
            {
                resolve();
            }

            foreach (var edmType in _typeFactory.LoadedTypes.Values)
            {
                edmType.SetReadOnly();
            }

            objectItemCollection.AddLoadedTypes(_typeFactory.LoadedTypes);
            objectItemCollection.OSpaceTypesLoaded = true;
        }
        public void LoadTypes(EdmItemCollection edmItemCollection, ObjectItemCollection objectItemCollection)
        {
            DebugCheck.NotNull(edmItemCollection);
            DebugCheck.NotNull(objectItemCollection);

            foreach (var cSpaceType in edmItemCollection.OfType <EdmType>().Where(
                         t => t.BuiltInTypeKind == BuiltInTypeKind.EntityType ||
                         t.BuiltInTypeKind == BuiltInTypeKind.EnumType ||
                         t.BuiltInTypeKind == BuiltInTypeKind.ComplexType))
            {
                var clrType = cSpaceType.GetClrType();
                if (clrType != null)
                {
                    var oSpaceType = _typeFactory.TryCreateType(clrType, cSpaceType);
                    if (oSpaceType != null)
                    {
                        Debug.Assert(!_typeFactory.CspaceToOspace.ContainsKey(cSpaceType));
                        _typeFactory.CspaceToOspace.Add(cSpaceType, oSpaceType);
                    }
                }
                else
                {
                    Debug.Assert(!(cSpaceType is EntityType || cSpaceType is ComplexType || cSpaceType is EnumType));
                }
            }

            _typeFactory.CreateRelationships(edmItemCollection);

            foreach (var resolve in _typeFactory.ReferenceResolutions)
            {
                resolve();
            }

            foreach (var edmType in _typeFactory.LoadedTypes.Values)
            {
                edmType.SetReadOnly();
            }

            objectItemCollection.AddLoadedTypes(_typeFactory.LoadedTypes);
            objectItemCollection.OSpaceTypesLoaded = true;
        }
        [Fact] // CodePlex 1832
        public void Structural_annotations_are_read_into_metadata_properties()
        {
            var edmItemCollection = new EdmItemCollection(new[] { XDocument.Parse(CsdlWithStructs).CreateReader() });

            var entityType = edmItemCollection.OfType<EntityType>().Single(e => e.Name == "NorwegianAnimal");
            var entityAnnotation = entityType.MetadataProperties.Single(p => p.Name == "FoxAnnotations:TheSecretOfTheFox");

            var element = ((XElement)entityAnnotation.Value);
            Assert.Equal("FoxAnnotations", element.Name.Namespace);
            Assert.Equal("TheSecretOfTheFox", element.Name.LocalName);

            var innerElement = element.Elements().Single();
            Assert.Equal("", innerElement.Name.Namespace);
            Assert.Equal("Secret", innerElement.Name.LocalName);

            Assert.Equal("Ancient Mystery", innerElement.Attributes().Single(e => e.Name.LocalName == "Name").Value);

            var property = entityType.Properties.Single(p => p.Name == "WhatDoesItSay");
            var propertyAnnotation = property.MetadataProperties.Single(p => p.Name == "FoxAnnotations:TheSecretOfTheFox");

            element = ((XElement)propertyAnnotation.Value);
            Assert.Equal("FoxAnnotations", element.Name.Namespace);
            Assert.Equal("TheSecretOfTheFox", element.Name.LocalName);

            Assert.Equal(2, element.Elements().Count());

            Assert.True(element.Elements().All(e => e.Name.Namespace == "FoxAnnotations"));
            Assert.True(element.Elements().All(e => e.Name.LocalName == "Option"));

            Assert.Equal(
                new[] { "Hattie Hattie Hattie Ho", "Wa-pa-pa-pa-pa-pow!" },
                element.Elements().Attributes().Where(e => e.Name.LocalName == "Name").Select(a => a.Value));
        }