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

Incorporate API Review feedback #25124

Merged
merged 1 commit into from
Jun 25, 2021
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
7 changes: 7 additions & 0 deletions src/EFCore.Design/Properties/TypeForwards.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// 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.Runtime.CompilerServices;
using Microsoft.EntityFrameworkCore.Design;

[assembly: TypeForwardedTo(typeof(ICSharpHelper))]
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class RelationalCommandDiagnosticsLogger
private DateTimeOffset _suppressCommandExecuteExpiration;
private DateTimeOffset _suppressDataReaderDisposingExpiration;

private readonly TimeSpan _loggingConfigCacheTime;
private readonly TimeSpan _loggingCacheTime;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand All @@ -48,8 +48,8 @@ public RelationalCommandDiagnosticsLogger(
IInterceptors? interceptors = null)
: base(loggerFactory, loggingOptions, diagnosticSource, loggingDefinitions, contextLogger, interceptors)
{
_loggingConfigCacheTime = contextOptions.FindExtension<CoreOptionsExtension>()?.LoggingConfigCacheTime ??
CoreOptionsExtension.DefaultLoggingConfigCacheTime;
_loggingCacheTime = contextOptions.FindExtension<CoreOptionsExtension>()?.LoggingCacheTime ??
CoreOptionsExtension.DefaultLoggingCacheTime;
}

#region CommandCreating
Expand All @@ -68,7 +68,7 @@ public virtual InterceptionResult<DbCommand> CommandCreating(
Guid connectionId,
DateTimeOffset startTime)
{
_suppressCommandCreateExpiration = startTime + _loggingConfigCacheTime;
_suppressCommandCreateExpiration = startTime + _loggingCacheTime;

var definition = RelationalResources.LogCommandCreating(this);

Expand Down Expand Up @@ -255,7 +255,7 @@ public virtual InterceptionResult<DbDataReader> CommandReaderExecuting(
Guid connectionId,
DateTimeOffset startTime)
{
_suppressCommandExecuteExpiration = startTime + _loggingConfigCacheTime;
_suppressCommandExecuteExpiration = startTime + _loggingCacheTime;

var definition = RelationalResources.LogExecutingCommand(this);

Expand Down Expand Up @@ -313,7 +313,7 @@ public virtual InterceptionResult<object> CommandScalarExecuting(
Guid connectionId,
DateTimeOffset startTime)
{
_suppressCommandExecuteExpiration = startTime + _loggingConfigCacheTime;
_suppressCommandExecuteExpiration = startTime + _loggingCacheTime;

var definition = RelationalResources.LogExecutingCommand(this);

Expand Down Expand Up @@ -371,7 +371,7 @@ public virtual InterceptionResult<int> CommandNonQueryExecuting(
Guid connectionId,
DateTimeOffset startTime)
{
_suppressCommandExecuteExpiration = startTime + _loggingConfigCacheTime;
_suppressCommandExecuteExpiration = startTime + _loggingCacheTime;

var definition = RelationalResources.LogExecutingCommand(this);

Expand Down Expand Up @@ -430,7 +430,7 @@ public virtual ValueTask<InterceptionResult<DbDataReader>> CommandReaderExecutin
DateTimeOffset startTime,
CancellationToken cancellationToken = default)
{
_suppressCommandExecuteExpiration = startTime + _loggingConfigCacheTime;
_suppressCommandExecuteExpiration = startTime + _loggingCacheTime;

var definition = RelationalResources.LogExecutingCommand(this);

Expand Down Expand Up @@ -489,7 +489,7 @@ public virtual ValueTask<InterceptionResult<object>> CommandScalarExecutingAsync
DateTimeOffset startTime,
CancellationToken cancellationToken = default)
{
_suppressCommandExecuteExpiration = startTime + _loggingConfigCacheTime;
_suppressCommandExecuteExpiration = startTime + _loggingCacheTime;

var definition = RelationalResources.LogExecutingCommand(this);

Expand Down Expand Up @@ -548,7 +548,7 @@ public virtual ValueTask<InterceptionResult<int>> CommandNonQueryExecutingAsync(
DateTimeOffset startTime,
CancellationToken cancellationToken = default)
{
_suppressCommandExecuteExpiration = startTime + _loggingConfigCacheTime;
_suppressCommandExecuteExpiration = startTime + _loggingCacheTime;

var definition = RelationalResources.LogExecutingCommand(this);

Expand Down Expand Up @@ -1238,7 +1238,7 @@ public virtual InterceptionResult DataReaderDisposing(
DateTimeOffset startTime,
TimeSpan duration)
{
_suppressDataReaderDisposingExpiration = startTime + _loggingConfigCacheTime;
_suppressDataReaderDisposingExpiration = startTime + _loggingCacheTime;

var definition = RelationalResources.LogDisposingDataReader(this);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class RelationalConnectionDiagnosticsLogger
private DateTimeOffset _suppressOpenExpiration;
private DateTimeOffset _suppressCloseExpiration;

private readonly TimeSpan _loggingConfigCacheTime;
private readonly TimeSpan _loggingCacheTime;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand All @@ -43,8 +43,8 @@ public RelationalConnectionDiagnosticsLogger(
IInterceptors? interceptors = null)
: base(loggerFactory, loggingOptions, diagnosticSource, loggingDefinitions, contextLogger, interceptors)
{
_loggingConfigCacheTime = contextOptions.FindExtension<CoreOptionsExtension>()?.LoggingConfigCacheTime ??
CoreOptionsExtension.DefaultLoggingConfigCacheTime;
_loggingCacheTime = contextOptions.FindExtension<CoreOptionsExtension>()?.LoggingCacheTime ??
CoreOptionsExtension.DefaultLoggingCacheTime;
}

#region ConnectionOpening
Expand All @@ -59,7 +59,7 @@ public virtual InterceptionResult ConnectionOpening(
IRelationalConnection connection,
DateTimeOffset startTime)
{
_suppressOpenExpiration = startTime + _loggingConfigCacheTime;
_suppressOpenExpiration = startTime + _loggingCacheTime;

var definition = RelationalResources.LogOpeningConnection(this);

Expand Down Expand Up @@ -103,7 +103,7 @@ public virtual ValueTask<InterceptionResult> ConnectionOpeningAsync(
DateTimeOffset startTime,
CancellationToken cancellationToken)
{
_suppressOpenExpiration = startTime + _loggingConfigCacheTime;
_suppressOpenExpiration = startTime + _loggingCacheTime;

var definition = RelationalResources.LogOpeningConnection(this);

Expand Down Expand Up @@ -300,7 +300,7 @@ public virtual InterceptionResult ConnectionClosing(
IRelationalConnection connection,
DateTimeOffset startTime)
{
_suppressCloseExpiration = startTime + _loggingConfigCacheTime;
_suppressCloseExpiration = startTime + _loggingCacheTime;

var definition = RelationalResources.LogClosingConnection(this);

Expand Down Expand Up @@ -343,7 +343,7 @@ public virtual ValueTask<InterceptionResult> ConnectionClosingAsync(
IRelationalConnection connection,
DateTimeOffset startTime)
{
_suppressCloseExpiration = startTime + _loggingConfigCacheTime;
_suppressCloseExpiration = startTime + _loggingCacheTime;

var definition = RelationalResources.LogClosingConnection(this);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ public RelationalModelRuntimeInitializer(
/// </summary>
/// <param name="model"> The model to initialize. </param>
/// <param name="designTime"> Whether the model should contain design-time configuration. </param>
/// <param name="preValidation">
/// <param name="prevalidation">
/// <see langword="true"/> indicates that only pre-validation initialization should be performed;
/// <see langword="false"/> indicates that only post-validation initialization should be performed.
/// </param>
protected override void InitializeModel(IModel model, bool designTime, bool preValidation)
protected override void InitializeModel(IModel model, bool designTime, bool prevalidation)
{
if (preValidation)
if (prevalidation)
{
model.AddRuntimeAnnotation(RelationalAnnotationNames.ModelDependencies, RelationalDependencies.RelationalModelDependencies);
}
Expand Down
8 changes: 8 additions & 0 deletions src/EFCore.Relational/Properties/TypeForwards.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// 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.Runtime.CompilerServices;
using Microsoft.EntityFrameworkCore.Design;

[assembly: TypeForwardedTo(typeof(MethodCallCodeFragment))]
[assembly: TypeForwardedTo(typeof(NestedClosureCodeFragment))]
6 changes: 3 additions & 3 deletions src/EFCore/DbContextOptionsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -640,10 +640,10 @@ public virtual DbContextOptionsBuilder AddInterceptors(params IInterceptor[] int
/// Defaults to one second.
/// </para>
/// </summary>
/// <param name="loggingConfigCacheTime"> The maximum time period over which to skip logging checks before checking again. </param>
/// <param name="timeSpan"> The maximum time period over which to skip logging checks before checking again. </param>
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public virtual DbContextOptionsBuilder LoggingConfigCacheTime(TimeSpan loggingConfigCacheTime)
=> WithOption(e => e.WithLoggingConfigCacheTime(loggingConfigCacheTime));
public virtual DbContextOptionsBuilder ConfigureLoggingCacheTime(TimeSpan timeSpan)
=> WithOption(e => e.WithLoggingCacheTime(timeSpan));

/// <summary>
/// <para>
Expand Down
6 changes: 3 additions & 3 deletions src/EFCore/DbContextOptionsBuilder`.cs
Original file line number Diff line number Diff line change
Expand Up @@ -519,9 +519,9 @@ public DbContextOptionsBuilder(DbContextOptions<TContext> options)
/// Defaults to one second.
/// </para>
/// </summary>
/// <param name="loggingConfigCacheTime"> The maximum time period over which to skip logging checks before checking again. </param>
/// <param name="timeSpan"> The maximum time period over which to skip logging checks before checking again. </param>
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public new virtual DbContextOptionsBuilder<TContext> LoggingConfigCacheTime(TimeSpan loggingConfigCacheTime)
=> (DbContextOptionsBuilder<TContext>)base.LoggingConfigCacheTime(loggingConfigCacheTime);
public new virtual DbContextOptionsBuilder<TContext> ConfigureLoggingCacheTime(TimeSpan timeSpan)
=> (DbContextOptionsBuilder<TContext>)base.ConfigureLoggingCacheTime(timeSpan);
}
}
20 changes: 10 additions & 10 deletions src/EFCore/Extensions/EntityFrameworkQueryableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2567,9 +2567,9 @@ internal static readonly MethodInfo TagWithMethodInfo
&& mi.GetParameters().Select(p => p.ParameterType)
.SequenceEqual(new Type[] { typeof(IQueryable<>).MakeGenericType(mi.GetGenericArguments()), typeof(string) }));

internal static readonly MethodInfo TagWithCallerInfoMethodInfo
internal static readonly MethodInfo TagWithCallSiteMethodInfo
= typeof(EntityFrameworkQueryableExtensions)
.GetRequiredDeclaredMethod(nameof(TagWith), mi => mi.GetParameters().Length == 3
.GetRequiredDeclaredMethod(nameof(TagWithCallSite), mi => mi.GetParameters().Length == 3
&& mi.GetParameters().Select(p => p.ParameterType)
.SequenceEqual(new Type[] { typeof(IQueryable<>).MakeGenericType(mi.GetGenericArguments()), typeof(string), typeof(int) }));

Expand Down Expand Up @@ -2609,16 +2609,16 @@ source.Provider is EntityQueryProvider
/// </summary>
/// <typeparam name="T"> The type of entity being queried. </typeparam>
/// <param name="source"> The source query. </param>
/// <param name="fromFile"> The file name where the method was called</param>
/// <param name="onLine"> The file line number where the method was called</param>
/// <param name="filePath"> The file name where the method was called</param>
/// <param name="lineNumber"> The file line number where the method was called</param>
/// <returns> A new query annotated with the given tag. </returns>
/// <exception cref="ArgumentNullException">
/// <paramref name="source" />
/// </exception>
public static IQueryable<T> TagWith<T>(
public static IQueryable<T> TagWithCallSite<T>(
this IQueryable<T> source,
[NotParameterized][CallerFilePath] string? fromFile = null,
[NotParameterized][CallerLineNumber] int onLine = 0)
[NotParameterized][CallerFilePath] string? filePath = null,
[NotParameterized][CallerLineNumber] int lineNumber = 0)
{
Check.NotNull(source, nameof(source));

Expand All @@ -2627,10 +2627,10 @@ source.Provider is EntityQueryProvider
? source.Provider.CreateQuery<T>(
Expression.Call(
instance: null,
method: TagWithCallerInfoMethodInfo.MakeGenericMethod(typeof(T)),
method: TagWithCallSiteMethodInfo.MakeGenericMethod(typeof(T)),
arg0: source.Expression,
arg1: Expression.Constant(fromFile),
arg2: Expression.Constant(onLine)))
arg1: Expression.Constant(filePath),
arg2: Expression.Constant(lineNumber)))
: source;
}

Expand Down
18 changes: 9 additions & 9 deletions src/EFCore/Infrastructure/CoreOptionsExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ public class CoreOptionsExtension : IDbContextOptionsExtension
private QueryTrackingBehavior _queryTrackingBehavior = QueryTrackingBehavior.TrackAll;
private IDictionary<(Type, Type?), Type>? _replacedServices;
private int? _maxPoolSize;
private TimeSpan _loggingConfigCacheTime = DefaultLoggingConfigCacheTime;
private TimeSpan _loggingCacheTime = DefaultLoggingCacheTime;
private bool _serviceProviderCachingEnabled = true;
private DbContextOptionsExtensionInfo? _info;
private IEnumerable<IInterceptor>? _interceptors;

/// <summary>
/// The default for how long EF Core will cache logging configuration in certain high-performance paths: one second.
/// See <see cref="DbContextOptionsBuilder.LoggingConfigCacheTime" />.
/// See <see cref="DbContextOptionsBuilder.ConfigureLoggingCacheTime" />.
/// </summary>
public static readonly TimeSpan DefaultLoggingConfigCacheTime = TimeSpan.FromSeconds(1);
public static readonly TimeSpan DefaultLoggingCacheTime = TimeSpan.FromSeconds(1);

private WarningsConfiguration _warningsConfiguration
= new WarningsConfiguration()
Expand Down Expand Up @@ -83,7 +83,7 @@ protected CoreOptionsExtension(CoreOptionsExtension copyFrom)
_warningsConfiguration = copyFrom.WarningsConfiguration;
_queryTrackingBehavior = copyFrom.QueryTrackingBehavior;
_maxPoolSize = copyFrom.MaxPoolSize;
_loggingConfigCacheTime = copyFrom.LoggingConfigCacheTime;
_loggingCacheTime = copyFrom.LoggingCacheTime;
_serviceProviderCachingEnabled = copyFrom.ServiceProviderCachingEnabled;
_interceptors = copyFrom.Interceptors?.ToList();

Expand Down Expand Up @@ -300,13 +300,13 @@ public virtual CoreOptionsExtension WithMaxPoolSize(int? maxPoolSize)
/// Creates a new instance with all options the same as for this instance, but with the given option changed.
/// It is unusual to call this method directly. Instead use <see cref="DbContextOptionsBuilder" />.
/// </summary>
/// <param name="loggingConfigCacheTime"> The maximum time period over which to skip logging checks before checking again. </param>
/// <param name="timeSpan"> The maximum time period over which to skip logging checks before checking again. </param>
/// <returns> A new instance with the option changed. </returns>
public virtual CoreOptionsExtension WithLoggingConfigCacheTime(TimeSpan loggingConfigCacheTime)
public virtual CoreOptionsExtension WithLoggingCacheTime(TimeSpan timeSpan)
{
var clone = Clone();

clone._loggingConfigCacheTime = loggingConfigCacheTime;
clone._loggingCacheTime = timeSpan;

return clone;
}
Expand Down Expand Up @@ -453,8 +453,8 @@ public virtual int? MaxPoolSize
/// cref="EntityFrameworkServiceCollectionExtensions.AddDbContextPool{TContext}(IServiceCollection,Action{DbContextOptionsBuilder},int)" />
/// method.
/// </summary>
public virtual TimeSpan LoggingConfigCacheTime
=> _loggingConfigCacheTime;
public virtual TimeSpan LoggingCacheTime
=> _loggingCacheTime;

/// <summary>
/// The options set from the <see cref="DbContextOptionsBuilder.AddInterceptors(IEnumerable{IInterceptor})" /> method.
Expand Down
13 changes: 1 addition & 12 deletions src/EFCore/Infrastructure/IndentedStringBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,6 @@ public virtual IndentedStringBuilder AppendLines(string value, bool skipFinalNew
return this;
}

/// <summary>
/// Appends the current indent and additional indent if provided.
/// </summary>
/// <returns> This builder so that additional calls can be chained. </returns>
public virtual IndentedStringBuilder AppendIndent()
{
_stringBuilder.Append(' ', _indent * IndentSize);

return this;
}

/// <summary>
/// Resets this builder ready to build a new string.
/// </summary>
Expand Down Expand Up @@ -233,7 +222,7 @@ private void DoIndent()
{
if (_indentPending && _indent > 0)
{
AppendIndent();
_stringBuilder.Append(' ', _indent * IndentSize);
}

_indentPending = false;
Expand Down
8 changes: 4 additions & 4 deletions src/EFCore/Infrastructure/ModelRuntimeInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ public virtual IModel Initialize(

model.ModelDependencies = initializer.Dependencies.ModelDependencies;

initializer.InitializeModel(model, designTime, preValidation: true);
initializer.InitializeModel(model, designTime, prevalidation: true);

if (validationLogger != null
&& model is IConventionModel)
{
initializer.Dependencies.ModelValidator.Validate(model, validationLogger);
}

initializer.InitializeModel(model, designTime, preValidation: false);
initializer.InitializeModel(model, designTime, prevalidation: false);

if (!designTime
&& model is Model mutableModel)
Expand Down Expand Up @@ -118,11 +118,11 @@ public virtual IModel Initialize(
/// </summary>
/// <param name="model"> The model to initialize. </param>
/// <param name="designTime"> Whether the model should contain design-time configuration. </param>
/// <param name="preValidation">
/// <param name="prevalidation">
/// <see langword="true"/> indicates that only pre-validation initialization should be performed;
/// <see langword="false"/> indicates that only post-validation initialization should be performed.
/// </param>
protected virtual void InitializeModel(IModel model, bool designTime, bool preValidation)
protected virtual void InitializeModel(IModel model, bool designTime, bool prevalidation)
{
}
}
Expand Down
Loading