Skip to content

Commit

Permalink
Address API Review feedback
Browse files Browse the repository at this point in the history
Part of #20409
  • Loading branch information
bricelam committed Mar 26, 2020
1 parent abcedd6 commit a1931d9
Show file tree
Hide file tree
Showing 40 changed files with 169 additions and 168 deletions.
10 changes: 5 additions & 5 deletions src/EFCore.Proxies/Properties/ProxiesStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/EFCore.Proxies/Properties/ProxiesStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,18 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="ProxyServicesMissing" xml:space="preserve">
<value>UseChangeDetectionProxies and UseLazyLoadingProxies each require AddEntityFrameworkProxies to be called on the internal service provider used.</value>
<value>UseChangeTrackingProxies and UseLazyLoadingProxies each require AddEntityFrameworkProxies to be called on the internal service provider used.</value>
</data>
<data name="ItsASeal" xml:space="preserve">
<value>Entity type '{entityType}' is sealed. UseChangeDetectionProxies requires all entity types to be public, unsealed, have virtual properties, and have a public or protected constructor. UseLazyLoadingProxies requires only the navigation properties be virtual.</value>
<value>Entity type '{entityType}' is sealed. UseChangeTrackingProxies requires all entity types to be public, unsealed, have virtual properties, and have a public or protected constructor. UseLazyLoadingProxies requires only the navigation properties be virtual.</value>
</data>
<data name="NonVirtualProperty" xml:space="preserve">
<value>Property '{property}' on entity type '{entityType}' is not virtual. UseChangeDetectionProxies requires all entity types to be public, unsealed, have virtual properties, and have a public or protected constructor. UseLazyLoadingProxies requires only the navigation properties be virtual.</value>
<value>Property '{property}' on entity type '{entityType}' is not virtual. UseChangeTrackingProxies requires all entity types to be public, unsealed, have virtual properties, and have a public or protected constructor. UseLazyLoadingProxies requires only the navigation properties be virtual.</value>
</data>
<data name="FieldProperty" xml:space="preserve">
<value>Property '{property}' on entity type '{entityType}' is mapped without a CLR property. UseChangeDetectionProxies requires all entity types to be public, unsealed, have virtual properties, and have a public or protected constructor. UseLazyLoadingProxies requires only the navigation properties be virtual.</value>
<value>Property '{property}' on entity type '{entityType}' is mapped without a CLR property. UseChangeTrackingProxies requires all entity types to be public, unsealed, have virtual properties, and have a public or protected constructor. UseLazyLoadingProxies requires only the navigation properties be virtual.</value>
</data>
<data name="ProxiesNotEnabled" xml:space="preserve">
<value>Unable to create proxy for '{entityType}' because proxies are not enabled. Call 'DbContextOptionsBuilder.UseChangeDetectionProxies' or 'DbContextOptionsBuilder.UseLazyLoadingProxies' to enable proxies.</value>
<value>Unable to create proxy for '{entityType}' because proxies are not enabled. Call 'DbContextOptionsBuilder.UseChangeTrackingProxies' or 'DbContextOptionsBuilder.UseLazyLoadingProxies' to enable proxies.</value>
</data>
</root>
24 changes: 12 additions & 12 deletions src/EFCore.Proxies/Proxies/Internal/ProxiesOptionsExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class ProxiesOptionsExtension : IDbContextOptionsExtension
{
private DbContextOptionsExtensionInfo _info;
private bool _useLazyLoadingProxies;
private bool _useChangeDetectionProxies;
private bool _useChangeTrackingProxies;
private bool _checkEquality;

/// <summary>
Expand All @@ -45,7 +45,7 @@ public ProxiesOptionsExtension()
protected ProxiesOptionsExtension([NotNull] ProxiesOptionsExtension copyFrom)
{
_useLazyLoadingProxies = copyFrom._useLazyLoadingProxies;
_useChangeDetectionProxies = copyFrom._useChangeDetectionProxies;
_useChangeTrackingProxies = copyFrom._useChangeTrackingProxies;
_checkEquality = copyFrom._checkEquality;
}

Expand Down Expand Up @@ -80,7 +80,7 @@ public virtual DbContextOptionsExtensionInfo Info
/// 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 bool UseChangeDetectionProxies => _useChangeDetectionProxies;
public virtual bool UseChangeTrackingProxies => _useChangeTrackingProxies;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand All @@ -96,7 +96,7 @@ public virtual DbContextOptionsExtensionInfo Info
/// 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 bool UseProxies => UseLazyLoadingProxies || UseChangeDetectionProxies;
public virtual bool UseProxies => UseLazyLoadingProxies || UseChangeTrackingProxies;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand All @@ -119,11 +119,11 @@ public virtual ProxiesOptionsExtension WithLazyLoading(bool useLazyLoadingProxie
/// 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 ProxiesOptionsExtension WithChangeDetection(bool useChangeDetectionProxies = true, bool checkEquality = true)
public virtual ProxiesOptionsExtension WithChangeTracking(bool useChangeTrackingProxies = true, bool checkEquality = true)
{
var clone = Clone();

clone._useChangeDetectionProxies = useChangeDetectionProxies;
clone._useChangeTrackingProxies = useChangeTrackingProxies;
clone._checkEquality = checkEquality;

return clone;
Expand Down Expand Up @@ -176,12 +176,12 @@ public ExtensionInfo(IDbContextOptionsExtension extension)
public override bool IsDatabaseProvider => false;

public override string LogFragment
=> _logFragment ??= Extension.UseLazyLoadingProxies && Extension.UseChangeDetectionProxies
? "using lazy-loading and change detection proxies "
=> _logFragment ??= Extension.UseLazyLoadingProxies && Extension.UseChangeTrackingProxies
? "using lazy-loading and change tracking proxies "
: Extension.UseLazyLoadingProxies
? "using lazy-loading proxies "
: Extension.UseChangeDetectionProxies
? "using change detection proxies "
: Extension.UseChangeTrackingProxies
? "using change tracking proxies "
: "";

public override long GetServiceProviderHashCode() => Extension.UseProxies ? 541 : 0;
Expand All @@ -191,8 +191,8 @@ public override void PopulateDebugInfo(IDictionary<string, string> debugInfo)
debugInfo["Proxies:" + nameof(ProxiesExtensions.UseLazyLoadingProxies)]
= (Extension._useLazyLoadingProxies ? 541 : 0).ToString(CultureInfo.InvariantCulture);

debugInfo["Proxies:" + nameof(ProxiesExtensions.UseChangeDetectionProxies)]
= (Extension._useChangeDetectionProxies ? 541 : 0).ToString(CultureInfo.InvariantCulture);
debugInfo["Proxies:" + nameof(ProxiesExtensions.UseChangeTrackingProxies)]
= (Extension._useChangeTrackingProxies ? 541 : 0).ToString(CultureInfo.InvariantCulture);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public virtual void ProcessModelFinalizing(IConventionModelBuilder modelBuilder,
ProxiesStrings.FieldProperty(navigation.Name, entityType.DisplayName()));
}

if (_options.UseChangeDetectionProxies
if (_options.UseChangeTrackingProxies
&& navigation.PropertyInfo.SetMethod?.IsVirtual == false)
{
throw new InvalidOperationException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Metadata.Conventions;
using Microsoft.EntityFrameworkCore.Metadata.Internal;

namespace Microsoft.EntityFrameworkCore.Proxies.Internal
{
Expand Down Expand Up @@ -37,10 +37,10 @@ public ProxyChangeTrackingConvention(
/// <param name="context"> Additional information associated with convention execution. </param>
public virtual void ProcessModelInitialized(IConventionModelBuilder modelBuilder, IConventionContext<IConventionModelBuilder> context)
{
if (_options?.UseChangeDetectionProxies == true)
if (_options?.UseChangeTrackingProxies == true)
{
modelBuilder.HasChangeTrackingStrategy(ChangeTrackingStrategy.ChangingAndChangedNotifications);
modelBuilder.HasAnnotation(ModelValidator.SkipChangeTrackingStrategyValidationAnnotation, "true");
modelBuilder.HasAnnotation(CoreAnnotationNames.SkipChangeTrackingStrategyValidationAnnotation, "true");
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore.Proxies/Proxies/Internal/ProxyFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private Type[] GetInterfacesToProxy(
interfacesToProxy.Add(_proxyLazyLoaderInterface);
}

if (options.UseChangeDetectionProxies)
if (options.UseChangeTrackingProxies)
{
var changeTrackingStrategy = entityType.GetChangeTrackingStrategy();
switch (changeTrackingStrategy)
Expand Down Expand Up @@ -205,7 +205,7 @@ private Castle.DynamicProxy.IInterceptor[] GetNotifyChangeInterceptors(
interceptors.Add(lazyLoadingInterceptor);
}

if (options.UseChangeDetectionProxies)
if (options.UseChangeTrackingProxies)
{
var changeTrackingStrategy = entityType.GetChangeTrackingStrategy();
switch (changeTrackingStrategy)
Expand Down
20 changes: 10 additions & 10 deletions src/EFCore.Proxies/ProxiesExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static class ProxiesExtensions
{
/// <summary>
/// <para>
/// Turns on the creation of change detection proxies.
/// Turns on the creation of change tracking proxies.
/// </para>
/// <para>
/// Note that this requires appropriate services to be available in the EF internal service provider. Normally this
Expand All @@ -30,20 +30,20 @@ public static class ProxiesExtensions
/// The options builder, as passed to <see cref="DbContext.OnConfiguring" />
/// or exposed AddDbContext.
/// </param>
/// <param name="useChangeDetectionProxies"> <c>True</c> to use change detection proxies; false to prevent their use. </param>
/// <param name="useChangeTrackingProxies"> <c>True</c> to use change tracking proxies; false to prevent their use. </param>
/// <param name="checkEquality"> <c>True</c> if proxy change detection should check if the incoming value is equal to the current value before notifying. Defaults to <c>True</c>. </param>
/// <returns> The same builder to allow method calls to be chained. </returns>
public static DbContextOptionsBuilder UseChangeDetectionProxies(
public static DbContextOptionsBuilder UseChangeTrackingProxies(
[NotNull] this DbContextOptionsBuilder optionsBuilder,
bool useChangeDetectionProxies = true,
bool useChangeTrackingProxies = true,
bool checkEquality = true)
{
Check.NotNull(optionsBuilder, nameof(optionsBuilder));

var extension = optionsBuilder.Options.FindExtension<ProxiesOptionsExtension>()
?? new ProxiesOptionsExtension();

extension = extension.WithChangeDetection(useChangeDetectionProxies, checkEquality);
extension = extension.WithChangeTracking(useChangeTrackingProxies, checkEquality);

((IDbContextOptionsBuilderInfrastructure)optionsBuilder).AddOrUpdateExtension(extension);

Expand All @@ -52,7 +52,7 @@ public static DbContextOptionsBuilder UseChangeDetectionProxies(

/// <summary>
/// <para>
/// Turns on the creation of change detection proxies.
/// Turns on the creation of change tracking proxies.
/// </para>
/// <para>
/// Note that this requires appropriate services to be available in the EF internal service provider. Normally this
Expand All @@ -65,15 +65,15 @@ public static DbContextOptionsBuilder UseChangeDetectionProxies(
/// The options builder, as passed to <see cref="DbContext.OnConfiguring" />
/// or exposed AddDbContext.
/// </param>
/// <param name="useChangeDetectionProxies"> <c>True</c> to use change detection proxies; false to prevent their use. </param>
/// <param name="useChangeTrackingProxies"> <c>True</c> to use change tracking proxies; false to prevent their use. </param>
/// <param name="checkEquality"> <c>True</c> if proxy change detection should check if the incoming value is equal to the current value before notifying. Defaults to <c>True</c>. </param>
/// <returns> The same builder to allow method calls to be chained. </returns>
public static DbContextOptionsBuilder<TContext> UseChangeDetectionProxies<TContext>(
public static DbContextOptionsBuilder<TContext> UseChangeTrackingProxies<TContext>(
[NotNull] this DbContextOptionsBuilder<TContext> optionsBuilder,
bool useChangeDetectionProxies = true,
bool useChangeTrackingProxies = true,
bool checkEquality = true)
where TContext : DbContext
=> (DbContextOptionsBuilder<TContext>)UseChangeDetectionProxies((DbContextOptionsBuilder)optionsBuilder, useChangeDetectionProxies, checkEquality);
=> (DbContextOptionsBuilder<TContext>)UseChangeTrackingProxies((DbContextOptionsBuilder)optionsBuilder, useChangeTrackingProxies, checkEquality);

/// <summary>
/// <para>
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Relational/Query/Internal/QueryingEnumerable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public virtual IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancella
public virtual DbCommand CreateDbCommand()
=> _relationalCommandCache
.GetRelationalCommand(_relationalQueryContext.ParameterValues)
.CreateCommand(
.CreateDbCommand(
new RelationalCommandParameterObject(
_relationalQueryContext.Connection,
_relationalQueryContext.ParameterValues,
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Relational/Storage/IRelationalCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Task<RelationalDataReader> ExecuteReaderAsync(
/// <param name="commandId"> The command correlation ID. </param>
/// <param name="commandMethod"> The method that will be called on the created command. </param>
/// <returns> The created command. </returns>
DbCommand CreateCommand(
DbCommand CreateDbCommand(
RelationalCommandParameterObject parameterObject,
Guid commandId,
DbCommandMethod commandMethod) => throw new NotImplementedException();
Expand Down
Loading

0 comments on commit a1931d9

Please sign in to comment.