Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.0] Fix places where skip navigations are missed #22884

Merged
merged 1 commit into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions src/EFCore/ChangeTracking/EntityEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,18 @@ public virtual NavigationEntry Navigation([NotNull] string propertyName)
/// navigation properties of this entity.
/// </summary>
public virtual IEnumerable<NavigationEntry> Navigations
=> InternalEntry.EntityType.GetNavigations().Select(
navigation => navigation.IsCollection
? (NavigationEntry)new CollectionEntry(InternalEntry, navigation)
: new ReferenceEntry(InternalEntry, navigation));
{
get
{
var entityType = InternalEntry.EntityType;
return entityType.GetNavigations()
.Concat<INavigationBase>(entityType.GetSkipNavigations())
.Select(
navigation => navigation.IsCollection
? (NavigationEntry)new CollectionEntry(InternalEntry, navigation.Name)
: new ReferenceEntry(InternalEntry, navigation.Name));
}
}

/// <summary>
/// Provides access to change tracking information and operations for a given
Expand Down Expand Up @@ -273,8 +281,16 @@ public virtual CollectionEntry Collection([NotNull] string propertyName)
/// collection navigation properties of this entity.
/// </summary>
public virtual IEnumerable<CollectionEntry> Collections
=> InternalEntry.EntityType.GetNavigations().Where(n => n.IsCollection)
.Select(navigation => new CollectionEntry(InternalEntry, navigation));
{
get
{
var entityType = InternalEntry.EntityType;
return entityType.GetNavigations()
.Concat<INavigationBase>(entityType.GetSkipNavigations())
.Where(navigation => navigation.IsCollection)
.Select(navigation => new CollectionEntry(InternalEntry, navigation.Name));
}
}

/// <summary>
/// <para>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public virtual async Task TraverseGraphAsync<TState>(
}

var internalEntityEntry = node.GetInfrastructure();
var navigations = internalEntityEntry.EntityType.GetNavigations();
var navigations = internalEntityEntry.EntityType.GetNavigations()
.Concat<INavigationBase>(internalEntityEntry.EntityType.GetSkipNavigations());
var stateManager = internalEntityEntry.StateManager;

foreach (var navigation in navigations)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ public virtual void Unsubscribe(InternalEntityEntry entry)

if (changeTrackingStrategy != ChangeTrackingStrategy.Snapshot)
{
foreach (var navigation in entityType.GetNavigations().Where(n => n.IsCollection))
foreach (var navigation in entityType.GetNavigations()
.Concat<INavigationBase>(entityType.GetSkipNavigations())
.Where(n => n.IsCollection))
{
AsINotifyCollectionChanged(entry, navigation, entityType, changeTrackingStrategy).CollectionChanged
-= entry.HandleINotifyCollectionChanged;
Expand Down
3 changes: 2 additions & 1 deletion src/EFCore/Extensions/EntityTypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,8 @@ public static IProperty GetProperty([NotNull] this IEntityType entityType, [NotN
var property = entityType.FindProperty(name);
if (property == null)
{
if (entityType.FindNavigation(name) != null)
if (entityType.FindNavigation(name) != null
|| entityType.FindSkipNavigation(name) != null)
{
throw new InvalidOperationException(
CoreStrings.PropertyIsNavigation(
Expand Down
11 changes: 9 additions & 2 deletions src/EFCore/Metadata/Internal/EntityTypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,19 @@ public static IEnumerable<IPropertyBase> GetNotificationProperties(
{
yield return navigation;
}

foreach (var navigation in entityType.GetSkipNavigations())
{
yield return navigation;
}
}
else
{
// ReSharper disable once AssignNullToNotNullAttribute
var property = (IPropertyBase)entityType.FindProperty(propertyName)
?? entityType.FindNavigation(propertyName);
var property = entityType.FindProperty(propertyName)
?? entityType.FindNavigation(propertyName)
?? (IPropertyBase)entityType.FindSkipNavigation(propertyName);

if (property != null)
{
yield return property;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.TestModels.ManyToManyModel;
using Microsoft.EntityFrameworkCore.TestUtilities;
Expand All @@ -22,10 +23,24 @@ protected override void ExecuteWithStrategyInTransaction(
Action<ManyToManyContext> nestedTestOperation2 = null,
Action<ManyToManyContext> nestedTestOperation3 = null)
{
base.ExecuteWithStrategyInTransaction(testOperation, nestedTestOperation1, nestedTestOperation2, nestedTestOperation3);
base.ExecuteWithStrategyInTransaction(
testOperation, nestedTestOperation1, nestedTestOperation2, nestedTestOperation3);

Fixture.Reseed();
}

protected override async Task ExecuteWithStrategyInTransactionAsync(
Func<ManyToManyContext, Task> testOperation,
Func<ManyToManyContext, Task> nestedTestOperation1 = null,
Func<ManyToManyContext, Task> nestedTestOperation2 = null,
Func<ManyToManyContext, Task> nestedTestOperation3 = null)
{
await base.ExecuteWithStrategyInTransactionAsync(
testOperation, nestedTestOperation1, nestedTestOperation2, nestedTestOperation3);

await Fixture.ReseedAsync();
}

protected override bool SupportsDatabaseDefaults
=> false;

Expand Down
Loading