/// <summary>
        /// Returns the association information for the specified navigation property.
        /// </summary>
        /// <param name="navigationProperty">The navigation property to return association information for</param>
        /// <returns>The association info</returns>
        internal AssociationInfo GetAssociationInfo(NavigationProperty navigationProperty)
        {
            return(_associationMap.GetOrAdd(navigationProperty.RelationshipType.FullName, associationName =>
            {
                AssociationType associationType = (AssociationType)navigationProperty.RelationshipType;

                if (!associationType.ReferentialConstraints.Any())
                {
                    // We only support EF models where FK info is part of the model.
                    throw Error.NotSupported(Resource.LinqToEntitiesProvider_UnableToRetrieveAssociationInfo, associationName);
                }

                string toRoleName = associationType.ReferentialConstraints[0].ToRole.Name;
                AssociationInfo associationInfo = new AssociationInfo()
                {
                    FKRole = toRoleName,
                    Name = GetAssociationName(navigationProperty, toRoleName),
                    ThisKey = associationType.ReferentialConstraints[0].ToProperties.Select(p => p.Name).ToArray(),
                    OtherKey = associationType.ReferentialConstraints[0].FromProperties.Select(p => p.Name).ToArray(),
                    IsRequired = associationType.RelationshipEndMembers[0].RelationshipMultiplicity == RelationshipMultiplicity.One
                };

                return associationInfo;
            }));
        }
        /// <summary>
        /// Creates an AssociationAttribute for the specified navigation property
        /// </summary>
        /// <param name="navigationProperty">The navigation property that corresponds to the association (it identifies the end points)</param>
        /// <returns>A new AssociationAttribute that describes the given navigation property association</returns>
        internal AssociationAttribute CreateAssociationAttribute(NavigationProperty navigationProperty)
        {
            AssociationInfo assocInfo    = GetAssociationInfo(navigationProperty);
            bool            isForeignKey = navigationProperty.FromEndMember.Name == assocInfo.FKRole;
            string          thisKey;
            string          otherKey;

            if (isForeignKey)
            {
                thisKey  = String.Join(",", assocInfo.ThisKey);
                otherKey = String.Join(",", assocInfo.OtherKey);
            }
            else
            {
                otherKey = String.Join(",", assocInfo.ThisKey);
                thisKey  = String.Join(",", assocInfo.OtherKey);
            }

            AssociationAttribute assocAttrib = new AssociationAttribute(assocInfo.Name, thisKey, otherKey);

            assocAttrib.IsForeignKey = isForeignKey;
            return(assocAttrib);
        }
        /// <summary>
        /// Returns the association information for the specified navigation property.
        /// </summary>
        /// <param name="navigationProperty">The navigation property to return association information for</param>
        /// <returns>The association info</returns>
        internal AssociationInfo GetAssociationInfo(NavigationProperty navigationProperty)
        {
            return _associationMap.GetOrAdd(navigationProperty.RelationshipType.FullName, associationName =>
            {
                AssociationType associationType = (AssociationType)navigationProperty.RelationshipType;

                if (!associationType.ReferentialConstraints.Any())
                {
                    // We only support EF models where FK info is part of the model.
                    throw Error.NotSupported(Resource.LinqToEntitiesProvider_UnableToRetrieveAssociationInfo, associationName);
                }

                string toRoleName = associationType.ReferentialConstraints[0].ToRole.Name;
                AssociationInfo associationInfo = new AssociationInfo()
                {
                    FKRole = toRoleName,
                    Name = GetAssociationName(navigationProperty, toRoleName),
                    ThisKey = associationType.ReferentialConstraints[0].ToProperties.Select(p => p.Name).ToArray(),
                    OtherKey = associationType.ReferentialConstraints[0].FromProperties.Select(p => p.Name).ToArray(),
                    IsRequired = associationType.RelationshipEndMembers[0].RelationshipMultiplicity == RelationshipMultiplicity.One
                };

                return associationInfo;
            });
        }