Example #1
0
        public static string ToDebugString(
            [NotNull] this IReadOnlyForeignKey foreignKey,
            MetadataDebugStringOptions options,
            int indent = 0)
        {
            var builder      = new StringBuilder();
            var indentString = new string(' ', indent);

            builder.Append(indentString);

            var singleLine = (options & MetadataDebugStringOptions.SingleLine) != 0;

            if (singleLine)
            {
                builder.Append("ForeignKey: ");
            }

            builder
            .Append(foreignKey.DeclaringEntityType.DisplayName())
            .Append(" ")
            .Append(foreignKey.Properties.Format())
            .Append(" -> ")
            .Append(foreignKey.PrincipalEntityType.DisplayName())
            .Append(" ")
            .Append(foreignKey.PrincipalKey.Properties.Format());

            if (foreignKey.IsUnique)
            {
                builder.Append(" Unique");
            }

            if (foreignKey.IsOwnership)
            {
                builder.Append(" Ownership");
            }

            if (foreignKey.PrincipalToDependent != null)
            {
                builder.Append(" ToDependent: ").Append(foreignKey.PrincipalToDependent.Name);
            }

            if (foreignKey.DependentToPrincipal != null)
            {
                builder.Append(" ToPrincipal: ").Append(foreignKey.DependentToPrincipal.Name);
            }

            if (foreignKey.DeleteBehavior != DeleteBehavior.NoAction)
            {
                builder
                .Append(" ")
                .Append(foreignKey.DeleteBehavior);
            }

            if (!singleLine && (options & MetadataDebugStringOptions.IncludeAnnotations) != 0)
            {
                builder.Append(foreignKey.AnnotationsToDebugString(indent + 2));
            }

            return(builder.ToString());
        }