/// <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, DebugViewOptions 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 & DebugViewOptions.IncludeAnnotations) != 0) { builder.Append(model.AnnotationsToDebugString(indent)); } 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 IKey key, DebugViewOptions options, [NotNull] string indent = "") { var builder = new StringBuilder(); builder.Append(indent); var singleLine = (options & DebugViewOptions.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 & DebugViewOptions.IncludeAnnotations) != 0) { builder.Append(key.AnnotationsToDebugString(indent + " ")); } 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 IForeignKey foreignKey, DebugViewOptions options, [NotNull] string indent = "") { var builder = new StringBuilder(); builder.Append(indent); var singleLine = (options & DebugViewOptions.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 (!singleLine && (options & DebugViewOptions.IncludeAnnotations) != 0) { builder.Append(foreignKey.AnnotationsToDebugString(indent + " ")); } 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 IServiceProperty serviceProperty, DebugViewOptions options, [NotNull] string indent = "") { var builder = new StringBuilder(); builder.Append(indent); var singleLine = (options & DebugViewOptions.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 & DebugViewOptions.IncludeAnnotations) != 0) { builder.Append(serviceProperty.AnnotationsToDebugString(indent + " ")); } 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 IEntityType entityType, DebugViewOptions options, [NotNull] string indent = "") { var builder = new StringBuilder(); builder .Append(indent) .Append("EntityType: ") .Append(entityType.DisplayName()); if (entityType.BaseType != null) { builder.Append(" Base: ").Append(entityType.BaseType.DisplayName()); } 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 & DebugViewOptions.SingleLine) == 0) { var properties = entityType.GetDeclaredProperties().ToList(); if (properties.Count != 0) { builder.AppendLine().Append(indent).Append(" Properties: "); foreach (var property in properties) { builder.AppendLine().Append(property.ToDebugString(options, indent + " ")); } } var navigations = entityType.GetDeclaredNavigations().ToList(); if (navigations.Count != 0) { builder.AppendLine().Append(indent).Append(" Navigations: "); foreach (var navigation in navigations) { builder.AppendLine().Append(navigation.ToDebugString(options, indent + " ")); } } var serviceProperties = entityType.GetDeclaredServiceProperties().ToList(); if (serviceProperties.Count != 0) { builder.AppendLine().Append(indent).Append(" Service properties: "); foreach (var serviceProperty in serviceProperties) { builder.AppendLine().Append(serviceProperty.ToDebugString(options, indent + " ")); } } var keys = entityType.GetDeclaredKeys().ToList(); if (keys.Count != 0) { builder.AppendLine().Append(indent).Append(" Keys: "); foreach (var key in keys) { builder.AppendLine().Append(key.ToDebugString(options, indent + " ")); } } var fks = entityType.GetDeclaredForeignKeys().ToList(); if (fks.Count != 0) { builder.AppendLine().Append(indent).Append(" Foreign keys: "); foreach (var fk in fks) { builder.AppendLine().Append(fk.ToDebugString(options, indent + " ")); } } var indexes = entityType.GetDeclaredIndexes().ToList(); if (indexes.Count != 0) { builder.AppendLine().Append(indent).Append(" Indexes: "); foreach (var index in indexes) { builder.AppendLine().Append(index.ToDebugString(options, indent + " ")); } } if ((options & DebugViewOptions.IncludeAnnotations) != 0) { builder.Append(entityType.AnnotationsToDebugString(indent: indent + " ")); } } 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 IProperty property, DebugViewOptions options, [NotNull] string indent = "") { var builder = new StringBuilder(); builder.Append(indent); var singleLine = (options & DebugViewOptions.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.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()); } if (property.IsUnicode() == false) { builder.Append(" Ansi"); } if (property.GetPropertyAccessMode() != PropertyAccessMode.PreferField) { builder.Append(" PropertyAccessMode.").Append(property.GetPropertyAccessMode()); } if ((options & DebugViewOptions.IncludePropertyIndexes) != 0) { var indexes = property.GetPropertyIndexes(); if (indexes != null) { 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 & DebugViewOptions.IncludeAnnotations) != 0) { builder.Append(property.AnnotationsToDebugString(indent + " ")); } 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, DebugViewOptions options, [NotNull] string indent = "") { var builder = new StringBuilder(); builder.Append(indent); var singleLine = (options & DebugViewOptions.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.IsDependentToPrincipal() ? " ToPrincipal " : " ToDependent "); builder.Append(navigation.GetTargetType().DisplayName()); if (navigation.FindInverse() != null) { builder.Append(" Inverse: ").Append(navigation.FindInverse().Name); } if (navigation.GetPropertyAccessMode() != PropertyAccessMode.PreferField) { builder.Append(" PropertyAccessMode.").Append(navigation.GetPropertyAccessMode()); } if ((options & DebugViewOptions.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 & DebugViewOptions.IncludeAnnotations) != 0) { builder.Append(navigation.AnnotationsToDebugString(indent + " ")); } return(builder.ToString()); }