From 8e17a77bf3f04f88c7ef328ef18ceb37e408a579 Mon Sep 17 00:00:00 2001 From: Smit Patel Date: Mon, 18 Nov 2019 17:37:18 -0800 Subject: [PATCH] Query: Don't expose ICurrentDbContext on QCCD Resolves #17845 --- src/EFCore/Query/QueryCompilationContext.cs | 6 ++-- .../QueryCompilationContextDependencies.cs | 29 ++++++++++++------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/EFCore/Query/QueryCompilationContext.cs b/src/EFCore/Query/QueryCompilationContext.cs index 71d60801dc0..4746ff9995f 100644 --- a/src/EFCore/Query/QueryCompilationContext.cs +++ b/src/EFCore/Query/QueryCompilationContext.cs @@ -32,14 +32,12 @@ public QueryCompilationContext( QueryCompilationContextDependencies dependencies, bool async) { - var context = dependencies.CurrentContext.Context; - IsAsync = async; - IsTracking = context.ChangeTracker.QueryTrackingBehavior == QueryTrackingBehavior.TrackAll; + IsTracking = dependencies.IsTracking; IsBuffering = dependencies.IsRetryingExecutionStrategy; Model = dependencies.Model; ContextOptions = dependencies.ContextOptions; - ContextType = context.GetType(); + ContextType = dependencies.ContextType; Logger = dependencies.Logger; _queryTranslationPreprocessorFactory = dependencies.QueryTranslationPreprocessorFactory; diff --git a/src/EFCore/Query/QueryCompilationContextDependencies.cs b/src/EFCore/Query/QueryCompilationContextDependencies.cs index 95101aa3623..85e701248e2 100644 --- a/src/EFCore/Query/QueryCompilationContextDependencies.cs +++ b/src/EFCore/Query/QueryCompilationContextDependencies.cs @@ -1,6 +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; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; @@ -37,6 +38,7 @@ namespace Microsoft.EntityFrameworkCore.Query public sealed class QueryCompilationContextDependencies { private readonly IExecutionStrategyFactory _executionStrategyFactory; + private readonly ICurrentDbContext _currentContext; /// /// @@ -79,7 +81,7 @@ public QueryCompilationContextDependencies( Check.NotNull(contextOptions, nameof(contextOptions)); Check.NotNull(logger, nameof(logger)); - CurrentContext = currentContext; + _currentContext = currentContext; Model = model; QueryTranslationPreprocessorFactory = queryTranslationPreprocessorFactory; QueryableMethodTranslatingExpressionVisitorFactory = queryableMethodTranslatingExpressionVisitorFactory; @@ -92,9 +94,14 @@ public QueryCompilationContextDependencies( } /// - /// The cache being used to store value generator instances. + /// The CLR type of DbContext. /// - public ICurrentDbContext CurrentContext { get; } + public Type ContextType => _currentContext.Context.GetType(); + + /// + /// The flag indicating if default query tracking behavior is tracking. + /// + public bool IsTracking => _currentContext.Context.ChangeTracker.QueryTrackingBehavior == QueryTrackingBehavior.TrackAll; /// /// The model. @@ -149,7 +156,7 @@ public QueryCompilationContextDependencies With([NotNull] IModel model) QueryTranslationPostprocessorFactory, ShapedQueryCompilingExpressionVisitorFactory, _executionStrategyFactory, - CurrentContext, + _currentContext, ContextOptions, Logger); @@ -166,7 +173,7 @@ public QueryCompilationContextDependencies With([NotNull] IQueryTranslationPrepr QueryTranslationPostprocessorFactory, ShapedQueryCompilingExpressionVisitorFactory, _executionStrategyFactory, - CurrentContext, + _currentContext, ContextOptions, Logger); @@ -184,7 +191,7 @@ public QueryCompilationContextDependencies With( QueryTranslationPostprocessorFactory, ShapedQueryCompilingExpressionVisitorFactory, _executionStrategyFactory, - CurrentContext, + _currentContext, ContextOptions, Logger); @@ -202,7 +209,7 @@ public QueryCompilationContextDependencies With( queryTranslationPostprocessorFactory, ShapedQueryCompilingExpressionVisitorFactory, _executionStrategyFactory, - CurrentContext, + _currentContext, ContextOptions, Logger); @@ -220,7 +227,7 @@ public QueryCompilationContextDependencies With( QueryTranslationPostprocessorFactory, shapedQueryCompilingExpressionVisitorFactory, _executionStrategyFactory, - CurrentContext, + _currentContext, ContextOptions, Logger); @@ -237,7 +244,7 @@ public QueryCompilationContextDependencies With([NotNull] IExecutionStrategyFact QueryTranslationPostprocessorFactory, ShapedQueryCompilingExpressionVisitorFactory, executionStrategyFactory, - CurrentContext, + _currentContext, ContextOptions, Logger); @@ -271,7 +278,7 @@ public QueryCompilationContextDependencies With([NotNull] IDbContextOptions cont QueryTranslationPostprocessorFactory, ShapedQueryCompilingExpressionVisitorFactory, _executionStrategyFactory, - CurrentContext, + _currentContext, contextOptions, Logger); @@ -288,7 +295,7 @@ public QueryCompilationContextDependencies With([NotNull] IDiagnosticsLogger