/// <summary>
        ///     <para>
        ///         Creates a human-readable representation of the given metadata.
        ///     </para>
        ///     <para>
        ///         Warning: Do not rely on the format of the returned string.
        ///         It is designed for debugging only and may change arbitrarily between releases.
        ///     </para>
        /// </summary>
        /// <param name="columnMapping"> The metadata item. </param>
        /// <param name="options"> Options for generating the string. </param>
        /// <param name="indent"> The number of indent spaces to use before each new line. </param>
        /// <returns> A human-readable representation. </returns>
        public static string ToDebugString(
            [NotNull] this IFunctionColumnMapping columnMapping,
            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($"FunctionColumnMapping: ");
            }

            builder.Append(columnMapping.Property.Name).Append(" - ");

            builder.Append(columnMapping.Column.Name);

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

            return(builder.ToString());
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        public static string ToDebugString(
            [NotNull] this IDbFunctionParameter parameter,
            MetadataDebugStringOptions options,
            [NotNull] string indent = "")
        {
            var builder = new StringBuilder();

            builder
            .Append(indent)
            .Append("DbFunctionParameter: ");

            builder.Append(parameter.Name)
            .Append(" ")
            .Append(parameter.StoreType);

            if ((options & MetadataDebugStringOptions.SingleLine) == 0)
            {
                if ((options & MetadataDebugStringOptions.IncludeAnnotations) != 0)
                {
                    builder.Append(parameter.AnnotationsToDebugString(indent: indent + "  "));
                }
            }

            return(builder.ToString());
        }
Ejemplo n.º 3
0
        public static string ToDebugString(
            [NotNull] this IReadOnlySequence sequence,
            MetadataDebugStringOptions options,
            int indent = 0)
        {
            var builder      = new StringBuilder();
            var indentString = new string(' ', indent);

            builder
            .Append(indentString)
            .Append("Sequence: ");

            if (sequence.Schema != null)
            {
                builder
                .Append(sequence.Schema)
                .Append(".");
            }

            builder.Append(sequence.Name);

            if (!sequence.IsCyclic)
            {
                builder.Append(" Cyclic");
            }

            if (sequence.StartValue != 1)
            {
                builder.Append(" Start: ")
                .Append(sequence.StartValue);
            }

            if (sequence.IncrementBy != 1)
            {
                builder.Append(" IncrementBy: ")
                .Append(sequence.IncrementBy);
            }

            if (sequence.MinValue != null)
            {
                builder.Append(" Min: ")
                .Append(sequence.MinValue);
            }

            if (sequence.MaxValue != null)
            {
                builder.Append(" Max: ")
                .Append(sequence.MaxValue);
            }

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

            return(builder.ToString());
        }
        public static string ToDebugString(
            [NotNull] this IUniqueConstraint uniqueConstraint,
            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("Key: ");
            }

            builder
            .Append(uniqueConstraint.Name)
            .Append(" ")
            .Append(ColumnBase.Format(uniqueConstraint.Columns));

            if (uniqueConstraint.GetIsPrimaryKey())
            {
                builder.Append(" PrimaryKey");
            }

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

            return(builder.ToString());
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        public static string ToDebugString(
            [NotNull] this IModel model,
            MetadataDebugStringOptions options,
            [NotNull] string indent = "")
        {
            var builder = new StringBuilder();

            builder.Append(indent).Append("Model: ");

            if (model.GetPropertyAccessMode() != PropertyAccessMode.PreferField)
            {
                builder.Append(" PropertyAccessMode.").Append(model.GetPropertyAccessMode());
            }

            if (model.GetChangeTrackingStrategy() != ChangeTrackingStrategy.Snapshot)
            {
                builder.Append(" ChangeTrackingStrategy.").Append(model.GetChangeTrackingStrategy());
            }

            foreach (var entityType in model.GetEntityTypes())
            {
                builder.AppendLine().Append(entityType.ToDebugString(options, indent + "  "));
            }

            if ((options & MetadataDebugStringOptions.IncludeAnnotations) != 0)
            {
                builder.Append(model.AnnotationsToDebugString(indent));
            }

            return(builder.ToString());
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        public static string ToDebugString(
            [NotNull] this IColumnMapping columnMapping,
            MetadataDebugStringOptions options,
            [NotNull] string indent = "")
        {
            var builder = new StringBuilder();

            builder.Append(indent);

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

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

            builder
            .Append(columnMapping.Property.DeclaringEntityType.DisplayName())
            .Append(".")
            .Append(columnMapping.Property.Name)
            .Append(" - ");

            builder
            .Append(columnMapping.Column.Table.Name)
            .Append(".")
            .Append(columnMapping.Column.Name);

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

            return(builder.ToString());
        }
Ejemplo n.º 7
0
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        public static string ToDebugString(
            [NotNull] this IViewMapping viewMapping,
            MetadataDebugStringOptions options,
            [NotNull] string indent = "")
        {
            var builder = new StringBuilder();

            builder.Append(indent);

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

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

            builder.Append(viewMapping.EntityType.Name).Append(" - ");

            builder.Append(viewMapping.Table.Name);

            if (viewMapping.IncludesDerivedTypes)
            {
                builder.Append($" IncludesDerivedTypes");
            }

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

            return(builder.ToString());
        }
Ejemplo n.º 8
0
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        public static string ToDebugString(
            [NotNull] this IRelationalModel model,
            MetadataDebugStringOptions options,
            [NotNull] string indent = "")
        {
            var builder = new StringBuilder();

            builder.Append(indent).Append("DatabaseModel: ");

            foreach (var table in model.Tables)
            {
                builder.AppendLine().Append(table.ToDebugString(options, indent + "  "));
            }

            foreach (var view in model.Views)
            {
                builder.AppendLine().Append(view.ToDebugString(options, indent + "  "));
            }

            if ((options & MetadataDebugStringOptions.IncludeAnnotations) != 0)
            {
                builder.Append(model.AnnotationsToDebugString(indent));
            }

            return(builder.ToString());
        }
Ejemplo n.º 9
0
        public static string ToDebugString(
            [NotNull] this ITableMapping tableMapping,
            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("TableMapping: ");
            }

            builder.Append(tableMapping.EntityType.Name).Append(" - ");

            builder.Append(tableMapping.Table.Name);

            if (tableMapping.IncludesDerivedTypes)
            {
                builder.Append(" IncludesDerivedTypes");
            }

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

            return(builder.ToString());
        }
Ejemplo n.º 10
0
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        public static string ToDebugString(
            [NotNull] this ICheckConstraint constraint,
            MetadataDebugStringOptions options,
            [NotNull] string indent = "")
        {
            var builder = new StringBuilder();

            builder
            .Append(indent)
            .Append("Check: ");

            builder.Append(constraint.Name)
            .Append(" \"")
            .Append(constraint.Sql)
            .Append("\"");

            if ((options & MetadataDebugStringOptions.SingleLine) == 0)
            {
                if ((options & MetadataDebugStringOptions.IncludeAnnotations) != 0)
                {
                    builder.Append(constraint.AnnotationsToDebugString(indent: indent + "  "));
                }
            }

            return(builder.ToString());
        }
        public static string ToDebugString(
            [NotNull] this IStoreFunctionParameter parameter,
            MetadataDebugStringOptions options,
            int indent = 0)
        {
            var builder      = new StringBuilder();
            var indentString = new string(' ', indent);

            builder
            .Append(indentString)
            .Append("StoreFunctionParameter: ");

            builder.Append(parameter.Name)
            .Append(" ")
            .Append(parameter.Type);

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

            return(builder.ToString());
        }
Ejemplo n.º 12
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());
        }
Ejemplo n.º 13
0
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        public static string ToDebugString(
            [NotNull] this IKey key,
            MetadataDebugStringOptions options,
            [NotNull] string indent = "")
        {
            var builder = new StringBuilder();

            builder.Append(indent);

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

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

            builder.AppendJoin(
                ", ", key.Properties.Select(
                    p => singleLine
                        ? p.DeclaringEntityType.DisplayName() + "." + p.Name
                        : p.Name));

            if (key.IsPrimaryKey())
            {
                builder.Append(" PK");
            }

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

            return(builder.ToString());
        }
Ejemplo n.º 14
0
        public static string ToDebugString(
            [NotNull] this ISqlQuery sqlQuery,
            MetadataDebugStringOptions options,
            int indent = 0)
        {
            var builder      = new StringBuilder();
            var indentString = new string(' ', indent);

            builder
            .Append(indentString)
            .Append("SqlQuery: ");

            if (sqlQuery.Schema != null)
            {
                builder
                .Append(sqlQuery.Schema)
                .Append(".");
            }

            builder.Append(sqlQuery.Name);

            if ((options & MetadataDebugStringOptions.SingleLine) == 0)
            {
                if (sqlQuery.Sql != null)
                {
                    builder.AppendLine().Append(indentString).Append("  Sql: ");
                    builder.AppendLine().Append(indentString).Append(new string(' ', 4)).Append(sqlQuery.Sql);
                }

                var mappings = sqlQuery.EntityTypeMappings.ToList();
                if (mappings.Count != 0)
                {
                    builder.AppendLine().Append(indentString).Append("  EntityTypeMappings: ");
                    foreach (var mapping in mappings)
                    {
                        builder.AppendLine().Append(mapping.ToDebugString(options, indent + 4));
                    }
                }

                var columns = sqlQuery.Columns.ToList();
                if (columns.Count != 0)
                {
                    builder.AppendLine().Append(indentString).Append("  Columns: ");
                    foreach (var column in columns)
                    {
                        builder.AppendLine().Append(column.ToDebugString(options, indent + 4));
                    }
                }

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

            return(builder.ToString());
        }
Ejemplo n.º 15
0
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        public static string ToDebugString(
            [NotNull] this ITable table,
            MetadataDebugStringOptions options,
            [NotNull] string indent = "")
        {
            var builder = new StringBuilder();

            builder
            .Append(indent)
            .Append("Table: ");

            if (table.Schema != null)
            {
                builder
                .Append(table.Schema)
                .Append(".");
            }

            builder.Append(table.Name);

            if (!table.IsMigratable)
            {
                builder.Append(" NonMigratable");
            }

            if ((options & MetadataDebugStringOptions.SingleLine) == 0)
            {
                var mappings = table.EntityTypeMappings.ToList();
                if (mappings.Count != 0)
                {
                    builder.AppendLine().Append(indent).Append("  EntityTypeMappings: ");
                    foreach (var mapping in mappings)
                    {
                        builder.AppendLine().Append(mapping.ToDebugString(options, indent + "    "));
                    }
                }

                var columns = table.Columns.ToList();
                if (columns.Count != 0)
                {
                    builder.AppendLine().Append(indent).Append("  Properties: ");
                    foreach (var column in columns)
                    {
                        builder.AppendLine().Append(column.ToDebugString(options, indent + "    "));
                    }
                }

                if ((options & MetadataDebugStringOptions.IncludeAnnotations) != 0)
                {
                    builder.Append(table.AnnotationsToDebugString(indent: indent + "  "));
                }
            }

            return(builder.ToString());
        }
Ejemplo n.º 16
0
        /// <summary>
        ///     <para>
        ///         Creates a human-readable representation of the given metadata.
        ///     </para>
        ///     <para>
        ///         Warning: Do not rely on the format of the returned string.
        ///         It is designed for debugging only and may change arbitrarily between releases.
        ///     </para>
        /// </summary>
        /// <param name="function"> The metadata item. </param>
        /// <param name="options"> Options for generating the string. </param>
        /// <param name="indent"> The number of indent spaces to use before each new line. </param>
        /// <returns> A human-readable representation. </returns>
        public static string ToDebugString(
            [NotNull] this IStoreFunction function,
            MetadataDebugStringOptions options,
            int indent = 0)
        {
            var builder      = new StringBuilder();
            var indentString = new string(' ', indent);

            builder
            .Append(indentString)
            .Append("StoreFunction: ");

            if (function.ReturnType != null)
            {
                builder.Append(function.ReturnType);
            }
            else
            {
                builder.Append(function.EntityTypeMappings.FirstOrDefault()?.EntityType.DisplayName() ?? "");
            }

            builder.Append(" ");

            if (function.Schema != null)
            {
                builder
                .Append(function.Schema)
                .Append(".");
            }

            builder.Append(function.Name);

            if ((options & MetadataDebugStringOptions.SingleLine) == 0)
            {
                var parameters = function.Parameters.ToList();
                if (parameters.Count != 0)
                {
                    builder.AppendLine().Append(indentString).Append("  Parameters: ");
                    foreach (var parameter in parameters)
                    {
                        builder.AppendLine().Append(parameter.ToDebugString(options, indent + 4));
                    }
                }

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

            return(builder.ToString());
        }
Ejemplo n.º 17
0
        /// <summary>
        ///     <para>
        ///         Creates a human-readable representation of the given metadata.
        ///     </para>
        ///     <para>
        ///         Warning: Do not rely on the format of the returned string.
        ///         It is designed for debugging only and may change arbitrarily between releases.
        ///     </para>
        /// </summary>
        /// <param name="view"> The metadata item. </param>
        /// <param name="options"> Options for generating the string. </param>
        /// <param name="indent"> The number of indent spaces to use before each new line. </param>
        /// <returns> A human-readable representation. </returns>
        public static string ToDebugString(
            [NotNull] this IView view,
            MetadataDebugStringOptions options,
            int indent = 0)
        {
            var builder      = new StringBuilder();
            var indentString = new string(' ', indent);

            builder
            .Append(indentString)
            .Append("View: ");

            if (view.Schema != null)
            {
                builder
                .Append(view.Schema)
                .Append(".");
            }

            builder.Append(view.Name);

            if ((options & MetadataDebugStringOptions.SingleLine) == 0)
            {
                var mappings = view.EntityTypeMappings.ToList();
                if (mappings.Count != 0)
                {
                    builder.AppendLine().Append(indentString).Append("  EntityTypeMappings: ");
                    foreach (var mapping in mappings)
                    {
                        builder.AppendLine().Append(mapping.ToDebugString(options, indent + 4));
                    }
                }

                var columns = view.Columns.ToList();
                if (columns.Count != 0)
                {
                    builder.AppendLine().Append(indentString).Append("  Properties: ");
                    foreach (var column in columns)
                    {
                        builder.AppendLine().Append(column.ToDebugString(options, indent + 4));
                    }
                }

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

            return(builder.ToString());
        }
        public static string ToDebugString(
            [NotNull] this IRelationalModel model,
            MetadataDebugStringOptions options,
            int indent = 0)
        {
            var builder      = new StringBuilder();
            var indentString = new string(' ', indent);

            builder.Append(indentString).Append("RelationalModel: ");

            if (model.Collation != null)
            {
                builder.AppendLine().Append(indentString).Append("Collation: " + model.Collation);
            }

            foreach (var table in model.Tables)
            {
                builder.AppendLine().Append(table.ToDebugString(options, indent + 2));
            }

            foreach (var view in model.Views)
            {
                builder.AppendLine().Append(view.ToDebugString(options, indent + 2));
            }

            foreach (var function in model.Functions)
            {
                builder.AppendLine().Append(function.ToDebugString(options, indent + 2));
            }

            foreach (var query in model.Queries)
            {
                builder.AppendLine().Append(query.ToDebugString(options, indent + 2));
            }

            foreach (var sequence in model.Sequences)
            {
                builder.AppendLine().Append(sequence.ToDebugString(options, indent + 2));
            }

            if ((options & MetadataDebugStringOptions.IncludeAnnotations) != 0)
            {
                builder.Append(model.AnnotationsToDebugString(indent));
            }

            return(builder.ToString());
        }
Ejemplo n.º 19
0
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        public static string ToDebugString(
            [NotNull] this IDbFunction function,
            MetadataDebugStringOptions options,
            [NotNull] string indent = "")
        {
            var builder = new StringBuilder();

            builder
            .Append(indent)
            .Append("DbFunction: ");

            builder.Append(function.ReturnType.ShortDisplayName())
            .Append(" ");

            if (function.Schema != null)
            {
                builder
                .Append(function.Schema)
                .Append(".");
            }

            builder.Append(function.Name);

            if ((options & MetadataDebugStringOptions.SingleLine) == 0)
            {
                var parameters = function.Parameters.ToList();
                if (parameters.Count != 0)
                {
                    builder.AppendLine().Append(indent).Append("  Parameters: ");
                    foreach (var parameter in parameters)
                    {
                        builder.AppendLine().Append(parameter.ToDebugString(options, indent + "    "));
                    }
                }

                if ((options & MetadataDebugStringOptions.IncludeAnnotations) != 0)
                {
                    builder.Append(function.AnnotationsToDebugString(indent: indent + "  "));
                }
            }

            return(builder.ToString());
        }
        /// <summary>
        ///     <para>
        ///         Creates a human-readable representation of the given metadata.
        ///     </para>
        ///     <para>
        ///         Warning: Do not rely on the format of the returned string.
        ///         It is designed for debugging only and may change arbitrarily between releases.
        ///     </para>
        /// </summary>
        /// <param name="foreignKey"> The metadata item. </param>
        /// <param name="options"> Options for generating the string. </param>
        /// <param name="indent"> The number of indent spaces to use before each new line. </param>
        /// <returns> A human-readable representation. </returns>
        public static string ToDebugString(
            [NotNull] this IForeignKeyConstraint 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.Name)
            .Append(" ")
            .Append(foreignKey.Table.Name)
            .Append(" ")
            .Append(Column.Format(foreignKey.Columns))
            .Append(" -> ")
            .Append(foreignKey.PrincipalTable.Name)
            .Append(" ")
            .Append(Column.Format(foreignKey.PrincipalColumns));

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

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

            return(builder.ToString());
        }
Ejemplo n.º 21
0
        /// <summary>
        ///     <para>
        ///         Creates a human-readable representation of the given metadata.
        ///     </para>
        ///     <para>
        ///         Warning: Do not rely on the format of the returned string.
        ///         It is designed for debugging only and may change arbitrarily between releases.
        ///     </para>
        /// </summary>
        /// <param name="index"> The metadata item. </param>
        /// <param name="options"> Options for generating the string. </param>
        /// <param name="indent"> The number of indent spaces to use before each new line. </param>
        /// <returns> A human-readable representation. </returns>
        public static string ToDebugString(
            [NotNull] this IIndex index,
            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("Index: ");
            }

            builder
            .AppendJoin(
                ", ",
                index.Properties.Select(
                    p => singleLine
                            ? p.DeclaringEntityType.DisplayName() + "." + p.Name
                            : p.Name));

            builder.Append(" " +
                           index.Name ?? "<unnamed>");

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

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

            return(builder.ToString());
        }
Ejemplo n.º 22
0
        /// <summary>
        ///     <para>
        ///         Creates a human-readable representation of the given metadata.
        ///     </para>
        ///     <para>
        ///         Warning: Do not rely on the format of the returned string.
        ///         It is designed for debugging only and may change arbitrarily between releases.
        ///     </para>
        /// </summary>
        /// <param name="index"> The metadata item. </param>
        /// <param name="options"> Options for generating the string. </param>
        /// <param name="indent"> The number of indent spaces to use before each new line. </param>
        /// <returns> A human-readable representation. </returns>
        public static string ToDebugString(
            [NotNull] this ITableIndex index,
            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("Index: ");
            }

            builder
            .Append(index.Name)
            .Append(" ")
            .Append(ColumnBase.Format(index.Columns));

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

            if (!string.IsNullOrWhiteSpace(index.Filter))
            {
                builder
                .Append(" Filtered");
            }

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

            return(builder.ToString());
        }
Ejemplo n.º 23
0
        /// <summary>
        ///     <para>
        ///         Creates a human-readable representation of the given metadata.
        ///     </para>
        ///     <para>
        ///         Warning: Do not rely on the format of the returned string.
        ///         It is designed for debugging only and may change arbitrarily between releases.
        ///     </para>
        /// </summary>
        /// <param name="column"> The metadata item. </param>
        /// <param name="options"> Options for generating the string. </param>
        /// <param name="indent"> The number of indent spaces to use before each new line. </param>
        /// <returns> A human-readable representation. </returns>
        public static string ToDebugString(
            [NotNull] this ISqlQueryColumn column,
            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($"SqlQueryColumn: {column.Table.Name}.");
            }

            builder.Append(column.Name).Append(" (");

            builder.Append(column.StoreType).Append(")");

            if (column.IsNullable)
            {
                builder.Append(" Nullable");
            }
            else
            {
                builder.Append(" NonNullable");
            }

            builder.Append(")");

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

            return(builder.ToString());
        }
Ejemplo n.º 24
0
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        public static string ToDebugString(
            [NotNull] this IColumn column,
            MetadataDebugStringOptions options,
            [NotNull] string indent = "")
        {
            var builder = new StringBuilder();

            builder.Append(indent);

            var singleLine = (options & MetadataDebugStringOptions.SingleLine) != 0;
            if (singleLine)
            {
                builder.Append($"Column: {column.Table.Name}.");
            }

            builder.Append(column.Name).Append(" (");

            builder.Append(column.Type).Append(")");

            if (column.IsNullable)
            {
                builder.Append(" Nullable");
            }
            else
            {
                builder.Append(" NonNullable");
            }

            builder.Append(")");

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

            return builder.ToString();
        }
Ejemplo n.º 25
0
        /// <summary>
        ///     <para>
        ///         Creates a human-readable representation of the given metadata.
        ///     </para>
        ///     <para>
        ///         Warning: Do not rely on the format of the returned string.
        ///         It is designed for debugging only and may change arbitrarily between releases.
        ///     </para>
        /// </summary>
        /// <param name="serviceProperty"> The metadata item. </param>
        /// <param name="options"> Options for generating the string. </param>
        /// <param name="indent"> The number of indent spaces to use before each new line. </param>
        /// <returns> A human-readable representation. </returns>
        public static string ToDebugString(
            [NotNull] this IServiceProperty serviceProperty,
            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("Service property: ").Append(serviceProperty.DeclaringType.DisplayName()).Append(".");
            }

            builder.Append(serviceProperty.Name);

            if (serviceProperty.GetFieldName() == null)
            {
                builder.Append(" (no field, ");
            }
            else
            {
                builder.Append(" (").Append(serviceProperty.GetFieldName()).Append(", ");
            }

            builder.Append(serviceProperty.ClrType?.ShortDisplayName()).Append(")");

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

            return(builder.ToString());
        }
Ejemplo n.º 26
0
        /// <summary>
        ///     <para>
        ///         Creates a human-readable representation of the given metadata.
        ///     </para>
        ///     <para>
        ///         Warning: Do not rely on the format of the returned string.
        ///         It is designed for debugging only and may change arbitrarily between releases.
        ///     </para>
        /// </summary>
        /// <param name="table"> The metadata item. </param>
        /// <param name="options"> Options for generating the string. </param>
        /// <param name="indent"> The number of indent spaces to use before each new line. </param>
        /// <returns> A human-readable representation. </returns>
        public static string ToDebugString(
            [NotNull] this ITable table,
            MetadataDebugStringOptions options,
            int indent = 0)
        {
            var builder      = new StringBuilder();
            var indentString = new string(' ', indent);

            builder
            .Append(indentString)
            .Append("Table: ");

            if (table.Schema != null)
            {
                builder
                .Append(table.Schema)
                .Append(".");
            }

            builder.Append(table.Name);

            if (table.IsExcludedFromMigrations)
            {
                builder.Append(" ExcludedFromMigrations");
            }

            if ((options & MetadataDebugStringOptions.SingleLine) == 0)
            {
                var mappings = table.EntityTypeMappings.ToList();
                if (mappings.Count != 0)
                {
                    builder.AppendLine().Append(indentString).Append("  EntityTypeMappings: ");
                    foreach (var mapping in mappings)
                    {
                        builder.AppendLine().Append(mapping.ToDebugString(options, indent + 4));
                    }
                }

                var columns = table.Columns.ToList();
                if (columns.Count != 0)
                {
                    builder.AppendLine().Append(indentString).Append("  Columns: ");
                    foreach (var column in columns)
                    {
                        builder.AppendLine().Append(column.ToDebugString(options, indent + 4));
                    }
                }

                var checkConstraints = table.CheckConstraints.ToList();
                if (checkConstraints.Count != 0)
                {
                    builder.AppendLine().Append(indentString).Append("  Check constraints: ");
                    foreach (var checkConstraint in checkConstraints)
                    {
                        builder.AppendLine().Append(checkConstraint.ToDebugString(options, indent + 4));
                    }
                }

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

            return(builder.ToString());
        }
Ejemplo n.º 27
0
        /// <summary>
        ///     <para>
        ///         Creates a human-readable representation of the given metadata.
        ///     </para>
        ///     <para>
        ///         Warning: Do not rely on the format of the returned string.
        ///         It is designed for debugging only and may change arbitrarily between releases.
        ///     </para>
        /// </summary>
        /// <param name="entityType"> The entity type. </param>
        /// <param name="options"> Options for generating the string. </param>
        /// <param name="indent"> The number of indent spaces to use before each new line. </param>
        /// <returns> A human-readable representation. </returns>
        public static string ToDebugString(
            [NotNull] this IEntityType entityType,
            MetadataDebugStringOptions options,
            int indent = 0)
        {
            var builder      = new StringBuilder();
            var indentString = new string(' ', indent);

            builder
            .Append(indentString)
            .Append("EntityType: ")
            .Append(entityType.DisplayName());

            if (entityType.BaseType != null)
            {
                builder.Append(" Base: ").Append(entityType.BaseType.DisplayName());
            }

            if (entityType.HasSharedClrType)
            {
                builder.Append(" CLR Type: ").Append(entityType.ClrType.ShortDisplayName());
            }

            if (entityType.IsAbstract())
            {
                builder.Append(" Abstract");
            }

            if (entityType.FindPrimaryKey() == null)
            {
                builder.Append(" Keyless");
            }

            if (entityType.GetChangeTrackingStrategy() != ChangeTrackingStrategy.Snapshot)
            {
                builder.Append(" ChangeTrackingStrategy.").Append(entityType.GetChangeTrackingStrategy());
            }

            if ((options & MetadataDebugStringOptions.SingleLine) == 0)
            {
                var properties = entityType.GetDeclaredProperties().ToList();
                if (properties.Count != 0)
                {
                    builder.AppendLine().Append(indentString).Append("  Properties: ");
                    foreach (var property in properties)
                    {
                        builder.AppendLine().Append(property.ToDebugString(options, indent + 4));
                    }
                }

                var navigations = entityType.GetDeclaredNavigations().ToList();
                if (navigations.Count != 0)
                {
                    builder.AppendLine().Append(indentString).Append("  Navigations: ");
                    foreach (var navigation in navigations)
                    {
                        builder.AppendLine().Append(navigation.ToDebugString(options, indent + 4));
                    }
                }

                var skipNavigations = entityType.GetDeclaredSkipNavigations().ToList();
                if (skipNavigations.Count != 0)
                {
                    builder.AppendLine().Append(indentString).Append("  Skip navigations: ");
                    foreach (var skipNavigation in skipNavigations)
                    {
                        builder.AppendLine().Append(skipNavigation.ToDebugString(options, indent + 4));
                    }
                }

                var serviceProperties = entityType.GetDeclaredServiceProperties().ToList();
                if (serviceProperties.Count != 0)
                {
                    builder.AppendLine().Append(indentString).Append("  Service properties: ");
                    foreach (var serviceProperty in serviceProperties)
                    {
                        builder.AppendLine().Append(serviceProperty.ToDebugString(options, indent + 4));
                    }
                }

                var keys = entityType.GetDeclaredKeys().ToList();
                if (keys.Count != 0)
                {
                    builder.AppendLine().Append(indentString).Append("  Keys: ");
                    foreach (var key in keys)
                    {
                        builder.AppendLine().Append(key.ToDebugString(options, indent + 4));
                    }
                }

                var fks = entityType.GetDeclaredForeignKeys().ToList();
                if (fks.Count != 0)
                {
                    builder.AppendLine().Append(indentString).Append("  Foreign keys: ");
                    foreach (var fk in fks)
                    {
                        builder.AppendLine().Append(fk.ToDebugString(options, indent + 4));
                    }
                }

                var indexes = entityType.GetDeclaredIndexes().ToList();
                if (indexes.Count != 0)
                {
                    builder.AppendLine().Append(indentString).Append("  Indexes: ");
                    foreach (var index in indexes)
                    {
                        builder.AppendLine().Append(index.ToDebugString(options, indent + 4));
                    }
                }

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

            return(builder.ToString());
        }
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        public static string ToDebugString(
            [NotNull] this INavigation navigation,
            MetadataDebugStringOptions options,
            [NotNull] string indent = "")
        {
            var builder = new StringBuilder();

            builder.Append(indent);

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

            if (singleLine)
            {
                builder.Append($"Navigation: {navigation.DeclaringEntityType.DisplayName()}.");
            }

            builder.Append(navigation.Name);

            var field = navigation.GetFieldName();

            if (field == null)
            {
                builder.Append(" (no field, ");
            }
            else if (!field.EndsWith(">k__BackingField", StringComparison.Ordinal))
            {
                builder.Append($" ({field}, ");
            }
            else
            {
                builder.Append(" (");
            }

            builder.Append(navigation.ClrType?.ShortDisplayName()).Append(")");

            if (navigation.IsCollection)
            {
                builder.Append(" Collection");
            }

            builder.Append(navigation.IsOnDependent ? " ToPrincipal " : " ToDependent ");

            builder.Append(navigation.TargetEntityType.DisplayName());

            if (navigation.Inverse != null)
            {
                builder.Append(" Inverse: ").Append(navigation.Inverse.Name);
            }

            if (navigation.GetPropertyAccessMode() != PropertyAccessMode.PreferField)
            {
                builder.Append(" PropertyAccessMode.").Append(navigation.GetPropertyAccessMode());
            }

            if ((options & MetadataDebugStringOptions.IncludePropertyIndexes) != 0)
            {
                var indexes = navigation.GetPropertyIndexes();
                builder.Append(" ").Append(indexes.Index);
                builder.Append(" ").Append(indexes.OriginalValueIndex);
                builder.Append(" ").Append(indexes.RelationshipIndex);
                builder.Append(" ").Append(indexes.ShadowIndex);
                builder.Append(" ").Append(indexes.StoreGenerationIndex);
            }

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

            return(builder.ToString());
        }
Ejemplo n.º 29
0
        public static string ToDebugString(
            [NotNull] this ITable table,
            MetadataDebugStringOptions options,
            int indent = 0)
        {
            var builder      = new StringBuilder();
            var indentString = new string(' ', indent);

            builder
            .Append(indentString)
            .Append("Table: ");

            if (table.Schema != null)
            {
                builder
                .Append(table.Schema)
                .Append(".");
            }

            builder.Append(table.Name);

            if (table.IsExcludedFromMigrations)
            {
                builder.Append(" ExcludedFromMigrations");
            }

            if (table.PrimaryKey == null)
            {
                builder.Append(" Keyless");
            }
            else
            {
                if ((options & MetadataDebugStringOptions.SingleLine) == 0)
                {
                    builder.AppendLine();
                }

                builder.Append(table.PrimaryKey.ToDebugString(options, indent + 2));
            }

            if ((options & MetadataDebugStringOptions.SingleLine) == 0 && table.Comment != null)
            {
                builder
                .AppendLine()
                .Append(indentString)
                .AppendLine(" Comment:")
                .Append(indentString)
                .Append(table.Comment);
            }

            if ((options & MetadataDebugStringOptions.SingleLine) == 0)
            {
                var mappings = table.EntityTypeMappings.ToList();
                if (mappings.Count != 0)
                {
                    builder.AppendLine().Append(indentString).Append("  EntityTypeMappings: ");
                    foreach (var mapping in mappings)
                    {
                        builder.AppendLine().Append(mapping.ToDebugString(options, indent + 4));
                    }
                }

                var columns = table.Columns.ToList();
                if (columns.Count != 0)
                {
                    builder.AppendLine().Append(indentString).Append("  Columns: ");
                    foreach (var column in columns)
                    {
                        builder.AppendLine().Append(column.ToDebugString(options, indent + 4));
                    }
                }

                var foreignKeyConstraints = table.ForeignKeyConstraints.ToList();
                if (foreignKeyConstraints.Count != 0)
                {
                    builder.AppendLine().Append(indentString).Append("  ForeignKeyConstraints: ");
                    foreach (var foreignKeyConstraint in foreignKeyConstraints)
                    {
                        builder.AppendLine().Append(foreignKeyConstraint.ToDebugString(options, indent + 4));
                    }
                }

                var indexes = table.Indexes.ToList();
                if (indexes.Count != 0)
                {
                    builder.AppendLine().Append(indentString).Append("  Indexes: ");
                    foreach (var index in indexes)
                    {
                        builder.AppendLine().Append(index.ToDebugString(options, indent + 4));
                    }
                }

                var uniqueConstraints = table.UniqueConstraints.Where(uc => !uc.GetIsPrimaryKey()).ToList();
                if (uniqueConstraints.Count != 0)
                {
                    builder.AppendLine().Append(indentString).Append("  UniqueConstraints: ");
                    foreach (var uniqueConstraint in uniqueConstraints)
                    {
                        builder.AppendLine().Append(uniqueConstraint.ToDebugString(options, indent + 4));
                    }
                }

                var checkConstraints = table.CheckConstraints.ToList();
                if (checkConstraints.Count != 0)
                {
                    builder.AppendLine().Append(indentString).Append("  Check constraints: ");
                    foreach (var checkConstraint in checkConstraints)
                    {
                        builder.AppendLine().Append(checkConstraint.ToDebugString(options, indent + 4));
                    }
                }

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

            return(builder.ToString());
        }
Ejemplo n.º 30
0
        public static string ToDebugString(
            [NotNull] this IReadOnlyProperty property,
            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($"Property: {property.DeclaringEntityType.DisplayName()}.");
            }

            builder.Append(property.Name).Append(" (");

            var field = property.GetFieldName();

            if (field == null)
            {
                builder.Append("no field, ");
            }
            else if (!field.EndsWith(">k__BackingField", StringComparison.Ordinal))
            {
                builder.Append(field).Append(", ");
            }

            builder.Append(property.ClrType.ShortDisplayName()).Append(")");

            if (property.IsShadowProperty())
            {
                builder.Append(" Shadow");
            }

            if (property.IsIndexerProperty())
            {
                builder.Append(" Indexer");
            }

            if (!property.IsNullable)
            {
                builder.Append(" Required");
            }

            if (property.IsPrimaryKey())
            {
                builder.Append(" PK");
            }

            if (property.IsForeignKey())
            {
                builder.Append(" FK");
            }

            if (property.IsKey() &&
                !property.IsPrimaryKey())
            {
                builder.Append(" AlternateKey");
            }

            if (property.IsIndex())
            {
                builder.Append(" Index");
            }

            if (property.IsConcurrencyToken)
            {
                builder.Append(" Concurrency");
            }

            if (property.GetBeforeSaveBehavior() != PropertySaveBehavior.Save)
            {
                builder.Append(" BeforeSave:").Append(property.GetBeforeSaveBehavior());
            }

            if (property.GetAfterSaveBehavior() != PropertySaveBehavior.Save)
            {
                builder.Append(" AfterSave:").Append(property.GetAfterSaveBehavior());
            }

            if (property.ValueGenerated != ValueGenerated.Never)
            {
                builder.Append(" ValueGenerated.").Append(property.ValueGenerated);
            }

            if (property.GetMaxLength() != null)
            {
                builder.Append(" MaxLength(").Append(property.GetMaxLength()).Append(")");
            }

            if (property.IsUnicode() == false)
            {
                builder.Append(" Ansi");
            }

            if (property.GetPropertyAccessMode() != PropertyAccessMode.PreferField)
            {
                builder.Append(" PropertyAccessMode.").Append(property.GetPropertyAccessMode());
            }

            if ((options & MetadataDebugStringOptions.IncludePropertyIndexes) != 0 &&
                ((Annotatable)property).IsReadOnly)
            {
                var indexes = ((IProperty)property).GetPropertyIndexes();
                builder.Append(" ").Append(indexes.Index);
                builder.Append(" ").Append(indexes.OriginalValueIndex);
                builder.Append(" ").Append(indexes.RelationshipIndex);
                builder.Append(" ").Append(indexes.ShadowIndex);
                builder.Append(" ").Append(indexes.StoreGenerationIndex);
            }

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

            return(builder.ToString());
        }