Skip to content

Commit

Permalink
Move IIndex, INavigation and related extension methods to the interfaces
Browse files Browse the repository at this point in the history
Part of #19213
  • Loading branch information
AndriySvyryd committed Feb 19, 2021
1 parent 41c13cd commit 9c7717a
Show file tree
Hide file tree
Showing 29 changed files with 362 additions and 511 deletions.
2 changes: 1 addition & 1 deletion src/EFCore/ChangeTracking/CollectionEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ protected virtual InternalEntityEntry GetInternalTargetEntry([NotNull] object en
: InternalEntry.StateManager.GetOrCreateEntry(entity, Metadata.TargetEntityType);

private ICollectionLoader TargetLoader
=> _loader ??= Metadata is ISkipNavigation skipNavigation
=> _loader ??= Metadata is IRuntimeSkipNavigation skipNavigation
? skipNavigation.GetManyToManyLoader()
: new EntityFinderCollectionLoaderAdapter(
InternalEntry.StateManager.CreateEntityFinder(Metadata.TargetEntityType),
Expand Down
1 change: 1 addition & 0 deletions src/EFCore/Extensions/ConventionNavigationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace Microsoft.EntityFrameworkCore
/// <summary>
/// Extension methods for <see cref="IConventionNavigation" />.
/// </summary>
[Obsolete("Use IConventionNavigation")]
public static class ConventionNavigationExtensions
{
/// <summary>
Expand Down
90 changes: 0 additions & 90 deletions src/EFCore/Extensions/IndexExtensions.cs

This file was deleted.

1 change: 1 addition & 0 deletions src/EFCore/Extensions/MutableNavigationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace Microsoft.EntityFrameworkCore
/// <summary>
/// Extension methods for <see cref="IMutableNavigation" />.
/// </summary>
[Obsolete("Use IMutableNavigation")]
public static class MutableNavigationExtensions
{
/// <summary>
Expand Down
99 changes: 6 additions & 93 deletions src/EFCore/Extensions/NavigationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@

using System;
using System.Diagnostics;
using System.Text;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Utilities;

#nullable enable
Expand All @@ -18,6 +15,7 @@ namespace Microsoft.EntityFrameworkCore
/// <summary>
/// Extension methods for <see cref="IReadOnlyNavigation" />.
/// </summary>
[Obsolete("Use IReadOnlyNavigation")]
public static class NavigationExtensions
{
/// <summary>
Expand All @@ -30,7 +28,7 @@ public static class NavigationExtensions
/// type that points to the principal entity, otherwise <see langword="false" />.
/// </returns>
[DebuggerStepThrough]
[Obsolete("Use INavigation.IsOnDependent")]
[Obsolete("Use IReadOnlyNavigation.IsOnDependent")]
public static bool IsDependentToPrincipal([NotNull] this IReadOnlyNavigation navigation)
=> Check.NotNull(navigation, nameof(navigation)).IsOnDependent;

Expand All @@ -42,7 +40,7 @@ public static bool IsDependentToPrincipal([NotNull] this IReadOnlyNavigation nav
/// <see langword="true" /> if this is a collection property, false if it is a reference property.
/// </returns>
[DebuggerStepThrough]
[Obsolete("Use INavigation.IsCollection")]
[Obsolete("Use IReadOnlyNavigation.IsCollection")]
public static bool IsCollection([NotNull] this IReadOnlyNavigation navigation)
=> Check.NotNull(navigation, nameof(navigation)).IsCollection;

Expand All @@ -55,7 +53,7 @@ public static bool IsCollection([NotNull] this IReadOnlyNavigation navigation)
/// The inverse navigation, or <see langword="null" /> if none is defined.
/// </returns>
[DebuggerStepThrough]
[Obsolete("Use INavigation.Inverse")]
[Obsolete("Use IReadOnlyNavigation.Inverse")]
public static IReadOnlyNavigation? FindInverse([NotNull] this IReadOnlyNavigation navigation)
=> Check.NotNull(navigation, nameof(navigation)).Inverse;

Expand All @@ -66,7 +64,7 @@ public static bool IsCollection([NotNull] this IReadOnlyNavigation navigation)
/// <param name="navigation"> The navigation property to find the target entity type of. </param>
/// <returns> The target entity type. </returns>
[DebuggerStepThrough]
[Obsolete("Use INavigation.TargetEntityType")]
[Obsolete("Use IReadOnlyNavigation.TargetEntityType")]
public static IReadOnlyEntityType GetTargetType([NotNull] this IReadOnlyNavigation navigation)
=> Check.NotNull(navigation, nameof(navigation)).TargetEntityType;

Expand All @@ -75,93 +73,8 @@ public static IReadOnlyEntityType GetTargetType([NotNull] this IReadOnlyNavigati
/// </summary>
/// <param name="navigation"> The navigation property to find whether it should be eager loaded. </param>
/// <returns> A value indicating whether this navigation should be eager loaded by default. </returns>
[Obsolete("Use INavigation.IsEagerLoaded")]
[Obsolete("Use IReadOnlyNavigation.IsEagerLoaded")]
public static bool IsEagerLoaded([NotNull] this IReadOnlyNavigation navigation)
=> Check.NotNull(navigation, nameof(navigation)).IsEagerLoaded;

/// <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="navigation"> 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 IReadOnlyNavigation navigation,
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($"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
&& ((Annotatable)navigation).IsReadOnly)
{
var indexes = ((INavigation)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 + 2));
}

return builder.ToString();
}
}
}
69 changes: 0 additions & 69 deletions src/EFCore/Extensions/ServicePropertyExtensions.cs

This file was deleted.

Loading

0 comments on commit 9c7717a

Please sign in to comment.