/// <summary>
        /// Creates a new instance of resource type given the cspace structural type and mapping clr type.
        /// </summary>
        /// <param name="cspaceType">cspace structural type.</param>
        /// <param name="clrType">mapping clr type for the given structural type.</param>
        /// <param name="baseResourceType">the base resource type for the given resource type.</param>
        /// <param name="metadataCacheItem">Instance of ProviderMetadataCacheItem.</param>
        /// <returns>the new resource type instance created for the given cspace type.</returns>
        private static ResourceType CreateResourceType(
            StructuralType cspaceType,
            Type clrType,
            ResourceType baseResourceType,
            ProviderMetadataCacheItem metadataCacheItem)
        {
            ResourceTypeKind resourceTypeKind = cspaceType.BuiltInTypeKind == BuiltInTypeKind.EntityType ? ResourceTypeKind.EntityType : ResourceTypeKind.ComplexType;

            // We do not support open types in Object Context provider yet.
            ResourceType resourceType = new ResourceType(clrType, resourceTypeKind, baseResourceType, cspaceType.NamespaceName, cspaceType.Name, clrType.IsAbstract);
            if (GetEntityTypeDefaultStreamProperty(cspaceType))
            {
                resourceType.IsMediaLinkEntry = true;
            }

            // Add stream properties that are marked NamedStream in clrType to resourceType.
            AddStreamProperties(resourceType, clrType, baseResourceType == null);

            metadataCacheItem.AddResourceType(clrType, resourceType);
            var childTypes = metadataCacheItem.ChildTypesCache;
            childTypes.Add(resourceType, null);
            if (baseResourceType != null)
            {
                Debug.Assert(childTypes.ContainsKey(baseResourceType), "childTypes.ContainsKey(baseResourceType)");
                if (childTypes[baseResourceType] == null)
                {
                    childTypes[baseResourceType] = new List<ResourceType>();
                }

                childTypes[baseResourceType].Add(resourceType);
            }

#if !EF6Provider
            ObjectContextServiceProvider.PopulateAnnotations(cspaceType.MetadataProperties, resourceType.AddCustomAnnotation);
#endif
            return resourceType;
        }
        /// <summary>
        /// returns the new resource type instance
        /// </summary>
        /// <param name="type">backing clr type for the resource.</param>
        /// <param name="kind">kind of the resource.</param>
        /// <param name="baseType">base type of the resource.</param>
        /// <param name="metadataCacheItem">Instance of ProviderMetadataCacheItem.</param>
        /// <returns>returns a new instance of the resource type containing all the metadata.</returns>
        private static ResourceType CreateResourceType(
            Type type,
            ResourceTypeKind kind,
            ResourceType baseType,
            ProviderMetadataCacheItem metadataCacheItem)
        {
            ResourceType resourceType = new ResourceType(type, kind, baseType, type.Namespace, CommonUtil.GetModelTypeName(type), type.IsAbstract);
            resourceType.IsOpenType = false;

            // We need to look at inherited attributes as well so we pass true for inherit argument. 
            if (type.GetCustomAttributes(typeof(HasStreamAttribute), true /* inherit */).Length == 1)
            {
                resourceType.IsMediaLinkEntry = true;
            }

            // Add stream properties that are marked NamedStream in clrType to resourceType.
            AddStreamProperties(resourceType, type, baseType == null);

            metadataCacheItem.AddResourceType(type, resourceType);
            var childTypes = metadataCacheItem.ChildTypesCache;
            childTypes.Add(resourceType, null);
            if (baseType != null)
            {
                Debug.Assert(childTypes.ContainsKey(baseType), "childTypes.ContainsKey(baseType)");
                if (childTypes[baseType] == null)
                {
                    childTypes[baseType] = new List<ResourceType>();
                }

                childTypes[baseType].Add(resourceType);
            }

            return resourceType;
        }