///<summary>
 /// Sets a collection of literals as a property value on this entity.
 ///</summary>
 ///<param name="propertyName">Property Name</param>
 ///<param name="value">A collection of literals that are the property value.</param>
 ///<typeparam name="T">The type of the literal</typeparam>
 ///<exception cref="EntityFrameworkException">Thrown if the named property is not mapped.</exception>
 public void SetRelatedLiteralPropertiesCollection <T>(string propertyName, ICollection <T> value)
 {
     if (!IsAttached)
     {
         var literalsCollection = new LiteralsCollection <T>(value);
         _currentItemValues[propertyName] = literalsCollection;
     }
     else
     {
         object existing;
         LiteralsCollection <T> literalsCollection;
         if (_currentItemValues.TryGetValue(propertyName, out existing) && existing is LiteralsCollection <T> )
         {
             literalsCollection = existing as LiteralsCollection <T>;
         }
         else
         {
             var propertyHint = GetPropertyHint(propertyName);
             if (propertyHint.MappingType != PropertyMappingType.Property)
             {
                 throw new EntityFrameworkException(
                           "Cannot set related literals for property '{0}' on type '{1}' because the property is mapped as '{2}'",
                           propertyName, GetType().FullName, propertyHint.MappingType);
             }
             literalsCollection = new LiteralsCollection <T>(this, propertyHint.SchemaTypeUri);
             _currentItemValues[propertyName] = literalsCollection;
         }
         literalsCollection.Clear();
         foreach (var item in value)
         {
             literalsCollection.Add(item);
         }
     }
 }
        /// <summary>
        /// Returns the collection of literal values for a property of this entity
        /// </summary>
        /// <typeparam name="T">The type of literal value to return</typeparam>
        /// <param name="propertyName">The name of the property</param>
        /// <returns>The collection of literal values</returns>
        public LiteralsCollection <T> GetRelatedLiteralPropertiesCollection <T>(string propertyName)
        {
            if (!IsAttached)
            {
                object value;
                if (_currentItemValues.TryGetValue(propertyName, out value) &&
                    value is LiteralsCollection <T> )
                {
                    return(value as LiteralsCollection <T>);
                }
                var literalsCollection = new LiteralsCollection <T>(new T[0]);
                _currentItemValues[propertyName] = literalsCollection;
                return(literalsCollection);
            }

            if (_currentItemValues.ContainsKey(propertyName))
            {
                return(_currentItemValues[propertyName] as LiteralsCollection <T>);
            }

            var propertyHint = GetPropertyHint(propertyName);

            if (propertyHint.MappingType != PropertyMappingType.Property)
            {
                throw new EntityFrameworkException(
                          "Cannot retrieve related literals for property '{0}' on type '{1}' because the property is mapped as '{2}'",
                          propertyName, GetType().FullName, propertyHint.MappingType);
            }
            var properties = new LiteralsCollection <T>(this, propertyHint.SchemaTypeUri);

            _currentItemValues[propertyName] = properties;
            return(properties);
        }