private static IEnumerable <IPropertyConstraint> GetConstraints(NavigationProperty from, NavigationProperty to)
        {
            var fromProp         = from.GetProperty();
            var toProp           = to.GetProperty();
            var fromMultiplicity = from.FromEndMember.RelationshipMultiplicity;
            var toMultiplicity   = from.ToEndMember.RelationshipMultiplicity;

            if (fromMultiplicity == RelationshipMultiplicity.Many && toMultiplicity == RelationshipMultiplicity.Many)
            {
                yield return(CreateGenericConstraint(typeof(ManyToManyPropertyConstraint <,>), fromProp, toProp));

                yield return(CreateGenericConstraint(typeof(ManyToManyPropertyConstraint <,>), toProp, fromProp));
            }
            else if (fromMultiplicity == RelationshipMultiplicity.Many)
            {
                yield return(CreateGenericConstraint(typeof(ManyToOnePropertyConstraint <,>), fromProp, toProp));

                yield return(CreateGenericConstraint(typeof(OneToManyPropertyConstraint <,>), toProp, fromProp));
            }
            else if (toMultiplicity == RelationshipMultiplicity.Many)
            {
                yield return(CreateGenericConstraint(typeof(OneToManyPropertyConstraint <,>), fromProp, toProp));

                yield return(CreateGenericConstraint(typeof(ManyToOnePropertyConstraint <,>), toProp, fromProp));
            }
            else
            {
                yield return(CreateGenericConstraint(typeof(OneToOnePropertyConstraint <,>), fromProp, toProp));

                yield return(CreateGenericConstraint(typeof(OneToOnePropertyConstraint <,>), toProp, fromProp));
            }

            var fromForeignKey = GetForeignKeyConstraint(from);

            if (fromForeignKey != null)
            {
                yield return(fromForeignKey);
            }

            var toForeignKey = GetForeignKeyConstraint(to);

            if (toForeignKey != null)
            {
                yield return(toForeignKey);
            }
        }
        private static IPropertyConstraint GetForeignKeyConstraint(NavigationProperty navProp)
        {
            if (navProp.GetDependentProperties().Count() != 1 ||
                navProp.ToEndMember.GetEntityType().KeyProperties.Count != 1)
            {
                return(null);
            }

            var dependencyProp = navProp.GetDependentProperties().Single();
            var keyProp        = navProp.ToEndMember.GetEntityType().KeyProperties.Single();
            var fromType       = navProp.FromEndMember.GetEntityType().GetClrType();
            var toType         = navProp.ToEndMember.GetEntityType().GetClrType();

            var navPropInfo        = navProp.GetProperty();
            var foreignKeyPropInfo = fromType.GetProperty(dependencyProp);
            var keyPropInfo        = toType.GetProperty(keyProp);
            var keyType            = keyPropInfo.PropertyType;

            var type = typeof(ForeignKeyConstraint <, ,>)
                       .MakeGenericType(fromType, toType, keyType);

            return((IPropertyConstraint)Activator.CreateInstance(type, navPropInfo, foreignKeyPropInfo, keyPropInfo));
        }