private void CreateConceptualNavigationProperty(EntityType entity, IAssociation association)
        {
            IEntity principalEntity;
            IEntity dependentEntity;
            bool isParentEntity;
            string key;
            string toRole;
            string fromRole;
            ResolveConceptualAssociationValues(association, out principalEntity, out dependentEntity, out isParentEntity, out key, out toRole, out fromRole);

            //11/4/2012 If an entity has an association to itself then we will modify the key if it's the child association.
            bool isSelfReferencingChild = !isParentEntity && principalEntity == dependentEntity;
            if (!isSelfReferencingChild && !association.IsParentManyToMany())
            {
                var temp = fromRole;
                fromRole = toRole;
                toRole = temp;
            }

            // 11/4/2012 Updated to check to see if a self referencing entity exists then we check the too and from roles. By checking only the to and from roles if it's a self referencing this allows custom names to be picked up.
            var navigationProperty = principalEntity == dependentEntity
                ? entity.NavigationProperties.FirstOrDefault(n => n.Relationship.Equals(String.Concat(ConceptualSchema.Namespace, ".", key)) && n.ToRole.Equals(toRole) && n.FromRole.Equals(fromRole))
                : entity.NavigationProperties.FirstOrDefault(n => n.Relationship.Equals(String.Concat(ConceptualSchema.Namespace, ".", key)));

            if (navigationProperty == null)
            {
                navigationProperty = new NavigationProperty() { Name = association.Name };
                entity.NavigationProperties.Add(navigationProperty);
            }

            if (String.IsNullOrEmpty(navigationProperty.Name) || association.Name.StartsWith(navigationProperty.Name))
                navigationProperty.Name = association.Name;

            navigationProperty.Relationship = String.Concat(ConceptualSchema.Namespace, ".", key);
            navigationProperty.FromRole = fromRole;
            navigationProperty.ToRole = toRole;
        }
        private bool ValidateConceptualNavigationProperty(NavigationProperty nav)
        {
            var associationSet = ConceptualSchemaEntityContainer.AssociationSets.Where(a => a.Association == nav.Relationship).FirstOrDefault();
            if (associationSet == null)
                return false;

            var association = ConceptualSchema.Associations.Where(a => a.Name == associationSet.Association.Replace(String.Concat(ConceptualSchema.Namespace, "."), "")).FirstOrDefault();
            if (association == null)
                return false;

            var fromRoleEnd = association.Ends.Where(e => e.Role.Equals(nav.FromRole, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
            var toRoleEnd = association.Ends.Where(e => e.Role.Equals(nav.ToRole, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
            if (fromRoleEnd == null || toRoleEnd == null)
                return false;

            var isValidFromRoleEntity = ConceptualSchema.EntityTypes.Count(es => fromRoleEnd.Type.Replace(String.Concat(ConceptualSchema.Namespace, "."), "").Equals(es.Name, StringComparison.OrdinalIgnoreCase)) > 0;
            var isValidToRoleEntity = ConceptualSchema.EntityTypes.Count(es => toRoleEnd.Type.Replace(String.Concat(ConceptualSchema.Namespace, "."), "").Equals(es.Name, StringComparison.OrdinalIgnoreCase)) > 0;
            if (!isValidFromRoleEntity || !isValidToRoleEntity)
                return false;

            if (nav.FromRole.Equals(fromRoleEnd.Role, StringComparison.OrdinalIgnoreCase) && nav.ToRole.Equals(toRoleEnd.Role, StringComparison.OrdinalIgnoreCase))
                return true;

            return false;
        }