/// <summary>
        /// Returns a unique association name for the specified MetaAssociation
        /// </summary>
        /// <param name="metaAssociation">A <see cref="MetaAssociation"/>.</param>
        /// <returns>A <see cref="String"/> containing the association name.</returns>
        private string GetAssociationName(MetaAssociation metaAssociation)
        {
            lock (this._associationNameMap)
            {
                // We need a unique key for this association, so we use the MetaAssociation
                // itself. In the case of bi-directional associations, we use the FK side.
                if (!metaAssociation.IsForeignKey && metaAssociation.OtherMember != null)
                {
                    metaAssociation = metaAssociation.OtherMember.Association;
                }

                string associationName = null;
                if (!this._associationNameMap.TryGetValue(metaAssociation, out associationName))
                {
                    // names are always formatted non-FK side type name followed by FK side type name
                    // For example, the name for both ends of the PurchaseOrder/PurchaseOrderDetail
                    // association will be PurchaseOrder_PurchaseOrderDetail
                    if (metaAssociation.IsForeignKey)
                    {
                        associationName = string.Format(CultureInfo.InvariantCulture, "{0}_{1}", metaAssociation.OtherType.Name, metaAssociation.ThisMember.DeclaringType.Name);
                    }
                    else
                    {
                        associationName = string.Format(CultureInfo.InvariantCulture, "{0}_{1}", metaAssociation.ThisMember.DeclaringType.Name, metaAssociation.OtherType.Name);
                    }

                    associationName = TypeDescriptionContextBase.MakeUniqueName(associationName, this._associationNameMap.Values);
                    this._associationNameMap[metaAssociation] = associationName;
                }

                return(associationName);
            }
        }
        /// <summary>
        /// Returns an AssociationAttribute for the specified association member
        /// </summary>
        /// <param name="member">The metadata member corresponding to the association member</param>
        /// <returns>The Association attribute</returns>
        public System.ComponentModel.DataAnnotations.AssociationAttribute CreateAssociationAttribute(MetaDataMember member)
        {
            MetaAssociation metaAssociation = member.Association;

            string associationName = this.GetAssociationName(metaAssociation);
            string thisKey         = TypeDescriptionContextBase.FormatMemberList(metaAssociation.ThisKey.Select(p => p.Name));
            string otherKey        = TypeDescriptionContextBase.FormatMemberList(metaAssociation.OtherKey.Select(p => p.Name));

            System.ComponentModel.DataAnnotations.AssociationAttribute assocAttrib = new System.ComponentModel.DataAnnotations.AssociationAttribute(associationName, thisKey, otherKey);
            assocAttrib.IsForeignKey = metaAssociation.IsForeignKey;

            return(assocAttrib);
        }