/// <summary>
        /// Search for a Mapping metadata with the specified type key.
        /// </summary>
        /// <param name="identity">identity of the type</param>
        /// <param name="typeSpace">The dataspace that the type for which map needs to be returned belongs to</param>
        /// <param name="ignoreCase">true for case-insensitive lookup</param>
        /// <param name="map"></param>
        /// <returns>Returns false if no match found.</returns>
        internal override bool TryGetMap(string identity, DataSpace typeSpace, bool ignoreCase, out Map map)
        {
            EdmType cdmType = null;
            EdmType clrType = null;
            if (typeSpace == DataSpace.CSpace)
            {
                if (ignoreCase)
                {
                    // Get the correct casing of the identity first if we are asked to do ignore case
                    if (!m_edmCollection.TryGetItem(identity, true, out cdmType))
                    {
                        map = null;
                        return false;
                    }

                    identity = cdmType.Identity;
                }

                int index;
                if (cdmTypeIndexes.TryGetValue(identity, out index))
                {
                    map = (Map)this[index];
                    return true;
                }

                if (cdmType != null
                    ||
                    m_edmCollection.TryGetItem(identity, ignoreCase, out cdmType))
                {
                    // If the mapping is not already loaded, then get the mapping ospace type
                    m_objectCollection.TryGetOSpaceType(cdmType, out clrType);
                }
            }
            else if (typeSpace == DataSpace.OSpace)
            {
                if (ignoreCase)
                {
                    // Get the correct casing of the identity first if we are asked to do ignore case
                    if (!m_objectCollection.TryGetItem(identity, true, out clrType))
                    {
                        map = null;
                        return false;
                    }

                    identity = clrType.Identity;
                }

                int index;
                if (clrTypeIndexes.TryGetValue(identity, out index))
                {
                    map = (Map)this[index];
                    return true;
                }

                if (clrType != null
                    ||
                    m_objectCollection.TryGetItem(identity, ignoreCase, out clrType))
                {
                    // If the mapping is not already loaded, get the mapping cspace type
                    var cspaceTypeName = ObjectItemCollection.TryGetMappingCSpaceTypeIdentity(clrType);
                    m_edmCollection.TryGetItem(cspaceTypeName, out cdmType);
                }
            }

            if ((clrType == null)
                || (cdmType == null))
            {
                map = null;
                return false;
            }
            else
            {
                map = GetDefaultMapping(cdmType, clrType);
                return true;
            }
        }
 /// <summary>
 ///     Given a map, dereference the EdmItem, ensure that it is
 ///     an EdmType and return a TypeUsage for the type, otherwise
 ///     return null.
 /// </summary>
 /// <param name="map"> The OC map to use to get the EdmType </param>
 /// <returns> A TypeUsage for the mapped EdmType or null if no EdmType was mapped </returns>
 private static TypeUsage GetMappedTypeUsage(Map map)
 {
     TypeUsage typeUsage = null;
     if (null != map)
     {
         var item = map.EdmItem;
         var edmItem = item as EdmType;
         if (null != item
             && edmItem != null)
         {
             typeUsage = TypeUsage.Create(edmItem);
         }
     }
     return typeUsage;
 }
 /// <summary>
 /// Search for a Mapping metadata with the specified type key.
 /// </summary>
 /// <param name="identity">identity of the type</param>
 /// <param name="typeSpace">The dataspace that the type for which map needs to be returned belongs to</param>
 /// <param name="map"></param>
 /// <returns>Returns false if no match found.</returns>
 internal override bool TryGetMap(string identity, DataSpace typeSpace, out Map map)
 {
     return TryGetMap(identity, typeSpace, false /*ignoreCase*/, out map);
 }
        /// <summary>
        /// Search for a Mapping metadata with the specified type key.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="map"></param>
        /// <returns>Returns false if no match found.</returns>
        internal override bool TryGetMap(GlobalItem item, out Map map)
        {
            if (item == null)
            {
                map = null;
                return false;
            }

            var typeSpace = item.DataSpace;

            //For transient types just create a map on fly and return
            var edmType = item as EdmType;
            if (edmType != null)
            {
                if (Helper.IsTransientType(edmType))
                {
                    map = GetOCMapForTransientType(edmType, typeSpace);
                    if (map != null)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
            }
            return TryGetMap(item.Identity, typeSpace, out map);
        }
 /// <summary>
 ///     Search for a Mapping metadata with the specified type key.
 /// </summary>
 /// <param name="identity"> identity of the type </param>
 /// <param name="typeSpace"> The dataspace that the type for which map needs to be returned belongs to </param>
 /// <param name="ignoreCase"> true for case-insensitive lookup </param>
 /// <param name="map"> </param>
 /// <returns> Returns false if no match found. </returns>
 internal virtual bool TryGetMap(string identity, DataSpace typeSpace, bool ignoreCase, out Map map)
 {
     //will only be implemented by Mapping Item Collections
     throw Error.NotSupported();
 }
 /// <summary>
 ///     Search for a Mapping metadata with the specified type key.
 /// </summary>
 /// <param name="item"> </param>
 /// <param name="map"> </param>
 /// <returns> Returns false if no match found. </returns>
 internal virtual bool TryGetMap(GlobalItem item, out Map map)
 {
     //will only be implemented by Mapping Item Collections
     throw Error.NotSupported();
 }
 /// <summary>
 ///     Search for a Mapping metadata with the specified type key.
 /// </summary>
 /// <param name="item"> </param>
 /// <param name="map"> </param>
 /// <returns> Returns false if no match found. </returns>
 internal override bool TryGetMap(GlobalItem item, out Map map)
 {
     if (item == null)
     {
         map = null;
         return false;
     }
     var typeSpace = item.DataSpace;
     if (typeSpace != DataSpace.CSpace)
     {
         map = null;
         return false;
     }
     return TryGetMap(item.Identity, typeSpace, out map);
 }
 /// <summary>
 ///     Search for a Mapping metadata with the specified type key.
 /// </summary>
 /// <param name="identity"> identity of the type </param>
 /// <param name="typeSpace"> The dataspace that the type for which map needs to be returned belongs to </param>
 /// <param name="ignoreCase"> true for case-insensitive lookup </param>
 /// <param name="map"> </param>
 /// <returns> Returns false if no match found. </returns>
 internal override bool TryGetMap(string identity, DataSpace typeSpace, bool ignoreCase, out Map map)
 {
     if (typeSpace != DataSpace.CSpace)
     {
         throw new InvalidOperationException(Strings.Mapping_Storage_InvalidSpace(typeSpace));
     }
     return TryGetItem(identity, ignoreCase, out map);
 }
 // Add to the cache. If it is already present, then throw an exception
 private void AddInternal(Map storageMap)
 {
     storageMap.DataSpace = DataSpace.CSSpace;
     try
     {
         base.AddInternal(storageMap);
     }
     catch (ArgumentException e)
     {
         throw new MappingException(Strings.Mapping_Duplicate_Type(storageMap.EdmItem.Identity), e);
     }
 }