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

Christmas crackers: Add Property/Reference/etc overloads that take IProperty/INavigation #27058

Merged
merged 1 commit into from
Jan 4, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected override object NextValue(EntityEntry entry)
continue;
}

var value = entry.Property(property.Name).CurrentValue;
var value = entry.Property(property).CurrentValue;

var converter = property.GetTypeMapping().Converter;
if (converter != null)
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore/ChangeTracking/CollectionEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public CollectionEntry(InternalEntityEntry internalEntry, string name)
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
[EntityFrameworkInternal]
public CollectionEntry(InternalEntityEntry internalEntry, INavigation navigation)
: base(internalEntry, navigation)
public CollectionEntry(InternalEntityEntry internalEntry, INavigationBase navigationBase)
: base(internalEntry, navigationBase, collection: true)
{
LocalDetectChanges();
}
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore/ChangeTracking/CollectionEntry`.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public CollectionEntry(InternalEntityEntry internalEntry, string name)
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
[EntityFrameworkInternal]
public CollectionEntry(InternalEntityEntry internalEntry, INavigation navigation)
: base(internalEntry, navigation)
public CollectionEntry(InternalEntityEntry internalEntry, INavigationBase navigationBase)
: base(internalEntry, navigationBase)
{
}

Expand Down
129 changes: 112 additions & 17 deletions src/EFCore/ChangeTracking/EntityEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,39 @@ public virtual DbContext Context
public virtual IEntityType Metadata
=> InternalEntry.EntityType;

/// <summary>
/// Provides access to change tracking information and operations for a given property or navigation of this entity.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-entity-entries">Accessing tracked entities in EF Core</see> for more information and
/// examples.
/// </remarks>
/// <param name="propertyBase">The property or navigation to access information and operations for.</param>
/// <returns>An object that exposes change tracking information and operations for the given property.</returns>
public virtual MemberEntry Member(IPropertyBase propertyBase)
{
Check.NotNull(propertyBase, nameof(propertyBase));

return propertyBase switch
{
IProperty property => new PropertyEntry(InternalEntry, property),
INavigationBase navigation => navigation.IsCollection
? new CollectionEntry(InternalEntry, navigation)
: new ReferenceEntry(InternalEntry, (INavigation)navigation),
_ => throw new InvalidOperationException(
CoreStrings.PropertyNotFound(propertyBase.Name, InternalEntry.EntityType.DisplayName()))
};
}

/// <summary>
/// Provides access to change tracking information and operations for a given
/// property or navigation property of this entity.
/// property or navigation of this entity.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-entity-entries">Accessing tracked entities in EF Core</see> for more information and
/// examples.
/// </remarks>
/// <param name="propertyName">The property to access information and operations for.</param>
/// <param name="propertyName">The property or navigation to access information and operations for.</param>
/// <returns>An object that exposes change tracking information and operations for the given property.</returns>
public virtual MemberEntry Member(string propertyName)
{
Expand All @@ -163,9 +187,8 @@ public virtual MemberEntry Member(string propertyName)
}

/// <summary>
/// Provides access to change tracking information and operations for all
/// properties and navigation properties of this entity.
/// </summary>
/// Provides access to change tracking information and operations for all properties and navigations of this entity.
/// </summary>-
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-entity-entries">Accessing tracked entities in EF Core</see> for more information and
/// examples.
Expand All @@ -174,15 +197,33 @@ public virtual IEnumerable<MemberEntry> Members
=> Properties.Cast<MemberEntry>().Concat(Navigations);

/// <summary>
/// Provides access to change tracking information and operations for a given
/// navigation property of this entity.
/// Provides access to change tracking information and operations for a given navigation of this entity.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-entity-entries">Accessing tracked entities in EF Core</see>
/// and <see href="https://aka.ms/efcore-docs-changing-relationships">Changing foreign keys and navigations</see>
/// for more information and examples.
/// </remarks>
/// <param name="propertyName">The property to access information and operations for.</param>
/// <param name="navigationBase">The navigation to access information and operations for.</param>
/// <returns>An object that exposes change tracking information and operations for the given property.</returns>
public virtual NavigationEntry Navigation(INavigationBase navigationBase)
{
Check.NotNull(navigationBase, nameof(navigationBase));

return navigationBase.IsCollection
? new CollectionEntry(InternalEntry, navigationBase)
: new ReferenceEntry(InternalEntry, (INavigation)navigationBase);
}

/// <summary>
/// Provides access to change tracking information and operations for a given navigation of this entity.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-entity-entries">Accessing tracked entities in EF Core</see>
/// and <see href="https://aka.ms/efcore-docs-changing-relationships">Changing foreign keys and navigations</see>
/// for more information and examples.
/// </remarks>
/// <param name="propertyName">The navigation to access information and operations for.</param>
/// <returns>An object that exposes change tracking information and operations for the given property.</returns>
public virtual NavigationEntry Navigation(string propertyName)
{
Expand Down Expand Up @@ -234,8 +275,23 @@ public virtual IEnumerable<NavigationEntry> Navigations
}

/// <summary>
/// Provides access to change tracking information and operations for a given
/// property of this entity.
/// Provides access to change tracking information and operations for a given property of this entity.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-entity-entries">Accessing tracked entities in EF Core</see> for more information and
/// examples.
/// </remarks>
/// <param name="property">The property to access information and operations for.</param>
/// <returns>An object that exposes change tracking information and operations for the given property.</returns>
public virtual PropertyEntry Property(IProperty property)
{
Check.NotNull(property, nameof(property));

return new PropertyEntry(InternalEntry, property);
}

/// <summary>
/// Provides access to change tracking information and operations for a given property of this entity.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-entity-entries">Accessing tracked entities in EF Core</see> for more information and
Expand Down Expand Up @@ -263,17 +319,36 @@ public virtual IEnumerable<PropertyEntry> Properties

/// <summary>
/// Provides access to change tracking and loading information for a reference (i.e. non-collection)
/// navigation property that associates this entity to another entity.
/// navigation that associates this entity to another entity.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-entity-entries">Accessing tracked entities in EF Core</see>
/// and <see href="https://aka.ms/efcore-docs-changing-relationships">Changing foreign keys and navigations</see>
/// for more information and examples.
/// </remarks>
/// <param name="propertyName">The name of the navigation property.</param>
/// <param name="navigation">The reference navigation.</param>
/// <returns>
/// An object that exposes change tracking information and operations for the
/// given navigation property.
/// An object that exposes change tracking information and operations for the given navigation.
/// </returns>
public virtual ReferenceEntry Reference(INavigationBase navigation)
{
Check.NotNull(navigation, nameof(navigation));

return new ReferenceEntry(InternalEntry, (INavigation)navigation);
}

/// <summary>
/// Provides access to change tracking and loading information for a reference (i.e. non-collection)
/// navigation that associates this entity to another entity.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-entity-entries">Accessing tracked entities in EF Core</see>
/// and <see href="https://aka.ms/efcore-docs-changing-relationships">Changing foreign keys and navigations</see>
/// for more information and examples.
/// </remarks>
/// <param name="propertyName">The name of the navigation.</param>
/// <returns>
/// An object that exposes change tracking information and operations for the given navigation.
/// </returns>
public virtual ReferenceEntry Reference(string propertyName)
{
Expand All @@ -297,17 +372,37 @@ public virtual IEnumerable<ReferenceEntry> References

/// <summary>
/// Provides access to change tracking and loading information for a collection
/// navigation property that associates this entity to a collection of another entities.
/// navigation that associates this entity to a collection of another entities.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-entity-entries">Accessing tracked entities in EF Core</see>
/// and <see href="https://aka.ms/efcore-docs-changing-relationships">Changing foreign keys and navigations</see>
/// for more information and examples.
/// </remarks>
/// <param name="navigation">The collection navigation.</param>
/// <returns>
/// An object that exposes change tracking information and operations for the given navigation.
/// </returns>
public virtual CollectionEntry Collection(INavigationBase navigation)
{
Check.NotNull(navigation, nameof(navigation));

return new CollectionEntry(InternalEntry, navigation);
}

/// <summary>
/// Provides access to change tracking and loading information for a collection
/// navigation that associates this entity to a collection of another entities.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-entity-entries">Accessing tracked entities in EF Core</see>
/// and <see href="https://aka.ms/efcore-docs-changing-relationships">Changing foreign keys and navigations</see>
/// for more information and examples.
/// </remarks>
/// <param name="propertyName">The name of the navigation property.</param>
/// <param name="propertyName">The name of the navigation.</param>
/// <returns>
/// An object that exposes change tracking information and operations for the
/// given navigation property.
/// given navigation.
/// </returns>
public virtual CollectionEntry Collection(string propertyName)
{
Expand Down
Loading