Skip to content

Commit

Permalink
Code cleanup for EFCore (#22182)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajcvickers committed Aug 23, 2020
1 parent 7a2b4c3 commit 19a65f2
Show file tree
Hide file tree
Showing 346 changed files with 3,650 additions and 2,211 deletions.
22 changes: 13 additions & 9 deletions src/EFCore/ChangeTracking/ChangeTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,10 @@ private void TryDetectChanges()
/// </para>
/// <para>
/// Note that this method calls <see cref="DetectChanges" /> unless
/// <see cref="AutoDetectChangesEnabled" /> has been set to <see langword="false"/>.
/// <see cref="AutoDetectChangesEnabled" /> has been set to <see langword="false" />.
/// </para>
/// </summary>
/// <returns> <see langword="true"/> if there are changes to save, otherwise <see langword="false"/>. </returns>
/// <returns> <see langword="true" /> if there are changes to save, otherwise <see langword="false" />. </returns>
public virtual bool HasChanges()
{
TryDetectChanges();
Expand Down Expand Up @@ -231,7 +231,8 @@ public virtual void DetectChanges()
/// represent the current state of the database. This method is typically called by <see cref="DbContext.SaveChanges()" />
/// after changes have been successfully saved to the database.
/// </summary>
public virtual void AcceptAllChanges() => StateManager.AcceptAllChanges();
public virtual void AcceptAllChanges()
=> StateManager.AcceptAllChanges();

/// <summary>
/// <para>
Expand Down Expand Up @@ -402,7 +403,7 @@ Task IResettableService.ResetStateAsync(CancellationToken cancellationToken)
/// Stops tracking all currently tracked entities.
/// </para>
/// <para>
/// <see cref="DbContext"/> is designed to have a short lifetime where a new instance is created for each unit-of-work.
/// <see cref="DbContext" /> is designed to have a short lifetime where a new instance is created for each unit-of-work.
/// This manner means all tracked entities are discarded when the context is disposed at the end of each unit-of-work.
/// However, clearing all tracked entities using this method may be useful in situations where creating a new context
/// instance is not practical.
Expand All @@ -413,7 +414,7 @@ Task IResettableService.ResetStateAsync(CancellationToken cancellationToken)
/// This method is much more efficient at clearing all tracked entities from the context.
/// </para>
/// <para>
/// Note that this method does not generate <see cref="StateChanged"/> events since entities are not individually detached.
/// Note that this method does not generate <see cref="StateChanged" /> events since entities are not individually detached.
/// </para>
/// </summary>
public virtual void Clear()
Expand All @@ -440,22 +441,25 @@ public virtual DebugView DebugView
/// </summary>
/// <returns> A string that represents the current object. </returns>
[EditorBrowsable(EditorBrowsableState.Never)]
public override string ToString() => base.ToString();
public override string ToString()
=> base.ToString();

/// <summary>
/// Determines whether the specified object is equal to the current object.
/// </summary>
/// <param name="obj"> The object to compare with the current object. </param>
/// <returns> <see langword="true"/> if the specified object is equal to the current object; otherwise, <see langword="false"/>. </returns>
/// <returns> <see langword="true" /> if the specified object is equal to the current object; otherwise, <see langword="false" />. </returns>
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool Equals(object obj) => base.Equals(obj);
public override bool Equals(object obj)
=> base.Equals(obj);

/// <summary>
/// Serves as the default hash function.
/// </summary>
/// <returns> A hash code for the current object. </returns>
[EditorBrowsable(EditorBrowsableState.Never)]
public override int GetHashCode() => base.GetHashCode();
public override int GetHashCode()
=> base.GetHashCode();

#endregion
}
Expand Down
3 changes: 1 addition & 2 deletions src/EFCore/ChangeTracking/ChangeTrackerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static string ToDebugString(

private sealed class EntityEntryComparer : IComparer<InternalEntityEntry>
{
public static EntityEntryComparer Instance = new EntityEntryComparer();
public static readonly EntityEntryComparer Instance = new EntityEntryComparer();

public int Compare(InternalEntityEntry x, InternalEntityEntry y)
{
Expand Down Expand Up @@ -79,6 +79,5 @@ public int Compare(InternalEntityEntry x, InternalEntityEntry y)
return 0;
}
}

}
}
3 changes: 2 additions & 1 deletion src/EFCore/ChangeTracking/CollectionEntry`.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public CollectionEntry([NotNull] InternalEntityEntry internalEntry, [NotNull] IN
/// The <see cref="EntityEntry{TEntity}" /> to which this member belongs.
/// </summary>
/// <value> An entry for the entity that owns this member. </value>
public new virtual EntityEntry<TEntity> EntityEntry => new EntityEntry<TEntity>(InternalEntry);
public new virtual EntityEntry<TEntity> EntityEntry
=> new EntityEntry<TEntity>(InternalEntry);

/// <summary>
/// Gets or sets the value currently assigned to this property. If the current value is set using this property,
Expand Down
29 changes: 19 additions & 10 deletions src/EFCore/ChangeTracking/EntityEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public EntityEntry([NotNull] InternalEntityEntry internalEntry)
/// <summary>
/// Gets the entity being tracked by this entry.
/// </summary>
public virtual object Entity => InternalEntry.Entity;
public virtual object Entity
=> InternalEntry.Entity;

/// <summary>
/// <para>
Expand Down Expand Up @@ -114,17 +115,20 @@ public virtual void DetectChanges()
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
[EntityFrameworkInternal]
InternalEntityEntry IInfrastructure<InternalEntityEntry>.Instance => InternalEntry;
InternalEntityEntry IInfrastructure<InternalEntityEntry>.Instance
=> InternalEntry;

/// <summary>
/// Gets the context that is tracking the entity.
/// </summary>
public virtual DbContext Context => InternalEntry.StateManager.Context;
public virtual DbContext Context
=> InternalEntry.StateManager.Context;

/// <summary>
/// Gets the metadata about the shape of the entity, its relationships to other entities, and how it maps to the database.
/// </summary>
public virtual IEntityType Metadata => InternalEntry.EntityType;
public virtual IEntityType Metadata
=> InternalEntry.EntityType;

/// <summary>
/// Provides access to change tracking information and operations for a given
Expand Down Expand Up @@ -286,7 +290,8 @@ public virtual IEnumerable<CollectionEntry> Collections
/// true since any value is considered a valid key value.
/// </para>
/// </summary>
public virtual bool IsKeySet => InternalEntry.IsKeySet.IsSet;
public virtual bool IsKeySet
=> InternalEntry.IsKeySet.IsSet;

/// <summary>
/// Gets the current property values for this entity.
Expand Down Expand Up @@ -372,7 +377,8 @@ public virtual async Task<PropertyValues> GetDatabaseValuesAsync(CancellationTok
/// not yet have had its permanent key value created.
/// </para>
/// </summary>
public virtual void Reload() => Reload(GetDatabaseValues());
public virtual void Reload()
=> Reload(GetDatabaseValues());

/// <summary>
/// <para>
Expand Down Expand Up @@ -420,7 +426,8 @@ private IEntityFinder Finder
/// Returns a string that represents the current object.
/// </summary>
/// <returns> A string that represents the current object. </returns>
public override string ToString() => InternalEntry.ToString();
public override string ToString()
=> InternalEntry.ToString();

/// <summary>
/// <para>
Expand All @@ -442,16 +449,18 @@ public virtual DebugView DebugView
/// Determines whether the specified object is equal to the current object.
/// </summary>
/// <param name="obj"> The object to compare with the current object. </param>
/// <returns> <see langword="true"/> if the specified object is equal to the current object; otherwise, <see langword="false"/>. </returns>
/// <returns> <see langword="true" /> if the specified object is equal to the current object; otherwise, <see langword="false" />. </returns>
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool Equals(object obj) => base.Equals(obj);
public override bool Equals(object obj)
=> base.Equals(obj);

/// <summary>
/// Serves as the default hash function.
/// </summary>
/// <returns> A hash code for the current object. </returns>
[EditorBrowsable(EditorBrowsableState.Never)]
public override int GetHashCode() => base.GetHashCode();
public override int GetHashCode()
=> base.GetHashCode();

#endregion
}
Expand Down
3 changes: 2 additions & 1 deletion src/EFCore/ChangeTracking/EntityEntryEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public EntityEntryEventArgs(
/// <summary>
/// The <see cref="EntityEntry" /> for the entity.
/// </summary>
public virtual EntityEntry Entry => _entry ??= new EntityEntry(_internalEntityEntry);
public virtual EntityEntry Entry
=> _entry ??= new EntityEntry(_internalEntityEntry);
}
}
9 changes: 6 additions & 3 deletions src/EFCore/ChangeTracking/EntityEntryGraphNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public EntityEntryGraphNode(
/// <summary>
/// Gets the entry tracking information about this entity.
/// </summary>
public virtual EntityEntry SourceEntry => _sourceEntry == null ? null : new EntityEntry(_sourceEntry);
public virtual EntityEntry SourceEntry
=> _sourceEntry == null ? null : new EntityEntry(_sourceEntry);

/// <summary>
/// Gets the navigation property that is being traversed to reach this node in the graph.
Expand All @@ -52,7 +53,8 @@ public EntityEntryGraphNode(
/// <summary>
/// Gets the entry tracking information about this entity.
/// </summary>
public virtual EntityEntry Entry => new EntityEntry(_entry);
public virtual EntityEntry Entry
=> new EntityEntry(_entry);

/// <summary>
/// <para>
Expand All @@ -63,7 +65,8 @@ public EntityEntryGraphNode(
/// application code.
/// </para>
/// </summary>
InternalEntityEntry IInfrastructure<InternalEntityEntry>.Instance => _entry;
InternalEntityEntry IInfrastructure<InternalEntityEntry>.Instance
=> _entry;

/// <summary>
/// Creates a new node for the entity that is being traversed next in the graph.
Expand Down
3 changes: 2 additions & 1 deletion src/EFCore/ChangeTracking/EntityEntry`.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public EntityEntry([NotNull] InternalEntityEntry internalEntry)
/// <summary>
/// Gets the entity being tracked by this entry.
/// </summary>
public new virtual TEntity Entity => (TEntity)base.Entity;
public new virtual TEntity Entity
=> (TEntity)base.Entity;

/// <summary>
/// Provides access to change tracking information and operations for a given
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/ChangeTracking/EntryCurrentValueComparer`.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public int Compare(IUpdateEntry x, IUpdateEntry y)
/// </summary>
/// <param name="x"> The first object to compare. </param>
/// <param name="y"> The second object to compare. </param>
/// <returns> <see langword="true"/> if the specified objects are equal; otherwise, <see langword="false"/>. </returns>
/// <returns> <see langword="true" /> if the specified objects are equal; otherwise, <see langword="false" />. </returns>
public bool Equals(IUpdateEntry x, IUpdateEntry y)
=> Compare(x, y) == 0;

Expand Down
10 changes: 5 additions & 5 deletions src/EFCore/ChangeTracking/IDependentKeyValueFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public interface IDependentKeyValueFactory<TKey>
/// </summary>
/// <param name="valueBuffer"> The value buffer representing the entity instance. </param>
/// <param name="key"> The key instance. </param>
/// <returns> <see langword="true"/> if the key instance was created; <see langword="false"/> otherwise. </returns>
/// <returns> <see langword="true" /> if the key instance was created; <see langword="false" /> otherwise. </returns>
[ContractAnnotation("=>true, key:notnull; =>false, key:null")]
bool TryCreateFromBuffer(in ValueBuffer valueBuffer, out TKey key);

Expand All @@ -34,7 +34,7 @@ public interface IDependentKeyValueFactory<TKey>
/// </summary>
/// <param name="entry"> The entry tracking an entity instance. </param>
/// <param name="key"> The key instance. </param>
/// <returns> <see langword="true"/> if the key instance was created; <see langword="false"/> otherwise. </returns>
/// <returns> <see langword="true" /> if the key instance was created; <see langword="false" /> otherwise. </returns>
[ContractAnnotation("=>true, key:notnull; =>false, key:null")]
bool TryCreateFromCurrentValues([NotNull] IUpdateEntry entry, out TKey key);

Expand All @@ -44,7 +44,7 @@ public interface IDependentKeyValueFactory<TKey>
/// </summary>
/// <param name="entry"> The entry tracking an entity instance. </param>
/// <param name="key"> The key instance. </param>
/// <returns> <see langword="true"/> if the key instance was created; <see langword="false"/> otherwise. </returns>
/// <returns> <see langword="true" /> if the key instance was created; <see langword="false" /> otherwise. </returns>
[ContractAnnotation("=>true, key:notnull; =>false, key:null")]
bool TryCreateFromPreStoreGeneratedCurrentValues([NotNull] IUpdateEntry entry, out TKey key);

Expand All @@ -53,7 +53,7 @@ public interface IDependentKeyValueFactory<TKey>
/// </summary>
/// <param name="entry"> The entry tracking an entity instance. </param>
/// <param name="key"> The key instance. </param>
/// <returns> <see langword="true"/> if the key instance was created; <see langword="false"/> otherwise. </returns>
/// <returns> <see langword="true" /> if the key instance was created; <see langword="false" /> otherwise. </returns>
[ContractAnnotation("=>true, key:notnull; =>false, key:null")]
bool TryCreateFromOriginalValues([NotNull] IUpdateEntry entry, out TKey key);

Expand All @@ -63,7 +63,7 @@ public interface IDependentKeyValueFactory<TKey>
/// </summary>
/// <param name="entry"> The entry tracking an entity instance. </param>
/// <param name="key"> The key instance. </param>
/// <returns> <see langword="true"/> if the key instance was created; <see langword="false"/> otherwise. </returns>
/// <returns> <see langword="true" /> if the key instance was created; <see langword="false" /> otherwise. </returns>
[ContractAnnotation("=>true, key:notnull; =>false, key:null")]
bool TryCreateFromRelationshipSnapshot([NotNull] IUpdateEntry entry, out TKey key);

Expand Down
4 changes: 2 additions & 2 deletions src/EFCore/ChangeTracking/Internal/ArrayPropertyValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Reflection;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Query;
Expand All @@ -34,7 +33,8 @@ public class ArrayPropertyValues : PropertyValues
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public ArrayPropertyValues([NotNull] InternalEntityEntry internalEntry, [NotNull] object[] values)
: base(internalEntry) => _values = values;
: base(internalEntry)
=> _values = values;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
7 changes: 4 additions & 3 deletions src/EFCore/ChangeTracking/Internal/ChangeDetector.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -55,15 +54,17 @@ public ChangeDetector(
/// 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 virtual void Suspend() => _suspended = true;
public virtual void Suspend()
=> _suspended = true;

/// <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 virtual void Resume() => _suspended = false;
public virtual void Resume()
=> _suspended = false;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public virtual IComparer<IUpdateEntry> Create([NotNull] IPropertyBase propertyBa
propertyBase.DeclaringType.DisplayName(),
propertyBase.Name,
modelType.ShortDisplayName(),
providerType.ShortDisplayName() ));
providerType.ShortDisplayName()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ protected override ValueComparer GetValueComparer(IProperty property)
/// 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>
protected override bool UseEntityVariable => false;
protected override bool UseEntityVariable
=> false;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
12 changes: 6 additions & 6 deletions src/EFCore/ChangeTracking/Internal/EntityEntryGraphIterator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,19 @@ public virtual async Task TraverseGraphAsync<TState>(
{
var targetEntry = stateManager.GetOrCreateEntry(relatedEntity, targetType);
await TraverseGraphAsync(
(EntityEntryGraphNode<TState>)node.CreateNode(node, targetEntry, navigation),
handleNode,
cancellationToken)
(EntityEntryGraphNode<TState>)node.CreateNode(node, targetEntry, navigation),
handleNode,
cancellationToken)
.ConfigureAwait(false);
}
}
else
{
var targetEntry = stateManager.GetOrCreateEntry(navigationValue, targetType);
await TraverseGraphAsync(
(EntityEntryGraphNode<TState>)node.CreateNode(node, targetEntry, navigation),
handleNode,
cancellationToken)
(EntityEntryGraphNode<TState>)node.CreateNode(node, targetEntry, navigation),
handleNode,
cancellationToken)
.ConfigureAwait(false);
}
}
Expand Down
Loading

0 comments on commit 19a65f2

Please sign in to comment.