/// <summary>
        ///
        /// </summary>
        /// <param name="end"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        private bool ValidateUniqueName(SchemaElement end, string name)
        {
            if (EndLookup.ContainsKey(name))
            {
                end.AddError(ErrorCode.AlreadyDefined, EdmSchemaErrorSeverity.Error,
                             System.Data.Entity.Strings.EndNameAlreadyDefinedDuplicate(name));
                return(false);
            }

            return(true);
        }
        /// <summary>
        ///     Remove a relationship end
        /// </summary>
        /// <param name="end"> the end to remove </param>
        /// <returns> true if item was in list </returns>
        public bool Remove(IRelationshipEnd end)
        {
            DebugCheck.NotNull(end);

            if (!IsEndValid(end))
            {
                return(false);
            }

            KeysInDefOrder.Remove(end.Name);
            var wasInList = EndLookup.Remove(end.Name);

            return(wasInList);
        }
        /// <summary>
        /// Remove a relationship end
        /// </summary>
        /// <param name="end">the end to remove</param>
        /// <returns>true if item was in list</returns>
        public bool Remove(IRelationshipEnd end)
        {
            Debug.Assert(end != null, "end parameter is null");

            if (!IsEndValid(end))
            {
                return(false);
            }

            KeysInDefOrder.Remove(end.Name);
            bool wasInList = EndLookup.Remove(end.Name);

            return(wasInList);
        }
        /// <summary>
        ///     Add a relationship end
        /// </summary>
        /// <param name="end"> the end to add </param>
        public void Add(IRelationshipEnd end)
        {
            DebugCheck.NotNull(end);

            var endElement = end as SchemaElement;

            Debug.Assert(endElement != null, "end is not a SchemaElement");

            // this should have been caught before this, just ignore it
            if (!IsEndValid(end))
            {
                return;
            }

            if (!ValidateUniqueName(endElement, end.Name))
            {
                return;
            }

            EndLookup.Add(end.Name, end);
            KeysInDefOrder.Add(end.Name);
        }
 /// <summary>
 ///     remove all elements from the collection
 /// </summary>
 public void Clear()
 {
     EndLookup.Clear();
     KeysInDefOrder.Clear();
 }
 public bool TryGetEnd(string name, out IRelationshipEnd end)
 {
     return(EndLookup.TryGetValue(name, out end));
 }
 /// <summary>
 ///     See if a relationship end is in the collection
 /// </summary>
 /// <param name="name"> the name of the end </param>
 /// <returns> true if the end name is in the collection </returns>
 public bool Contains(string name)
 {
     return(EndLookup.ContainsKey(name));
 }