diff --git a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs index b2571842ed6..e180d6f5856 100644 --- a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs @@ -104,6 +104,9 @@ private static readonly PropertyInfo Utf8JsonReaderTokenTypeProperty private static readonly MethodInfo PropertyGetTypeMappingMethod = typeof(IReadOnlyProperty).GetMethod(nameof(IReadOnlyProperty.GetTypeMapping), [])!; + private static readonly PropertyInfo QueryContextQueryLoggerProperty = + typeof(QueryContext).GetProperty(nameof(QueryContext.QueryLogger))!; + private readonly RelationalShapedQueryCompilingExpressionVisitor _parentVisitor; private readonly ISet? _tags; private readonly bool _isTracking; @@ -1738,9 +1741,7 @@ private Expression CreateJsonShapers( jsonReaderDataShaperLambdaParameter, innerShapersMap, innerFixupMap, - trackingInnerFixupMap, - _queryLogger, - _parentVisitor.Dependencies.LiftableConstantFactory).Rewrite(structuralTypeShaperMaterializer); + trackingInnerFixupMap).Rewrite(structuralTypeShaperMaterializer); var entityShaperMaterializerVariable = Variable( structuralTypeShaperMaterializer.Type, @@ -1889,9 +1890,7 @@ private sealed class JsonEntityMaterializerRewriter( ParameterExpression jsonReaderDataParameter, IDictionary innerShapersMap, IDictionary innerFixupMap, - IDictionary trackingInnerFixupMap, - IDiagnosticsLogger queryLogger, - ILiftableConstantFactory liftableConstantFactory) + IDictionary trackingInnerFixupMap) : ExpressionVisitor { private static readonly PropertyInfo JsonEncodedTextEncodedUtf8BytesProperty @@ -2013,11 +2012,7 @@ protected override Expression VisitSwitch(SwitchExpression switchExpression) New( JsonReaderManagerConstructor, jsonReaderDataParameter, - liftableConstantFactory.CreateLiftableConstant( - queryLogger, - static c => c.Dependencies.QueryLogger, - "queryLogger", - typeof(IDiagnosticsLogger)))), + MakeMemberAccess(QueryCompilationContext.QueryContextParameter, QueryContextQueryLoggerProperty))), // tokenType = jsonReaderManager.CurrentReader.TokenType Assign( tokenTypeVariable, @@ -2208,11 +2203,7 @@ void ProcessFixup(IDictionary fixupMap) New( JsonReaderManagerConstructor, jsonReaderDataParameter, - liftableConstantFactory.CreateLiftableConstant( - queryLogger, - static c => c.Dependencies.QueryLogger, - "queryLogger", - typeof(IDiagnosticsLogger)))); + MakeMemberAccess(QueryCompilationContext.QueryContextParameter, QueryContextQueryLoggerProperty))); readExpressions.Add( Block( @@ -2605,11 +2596,7 @@ internal ParameterExpression GenerateJsonReader(int jsonColumnIndex, ITypeBase s New( JsonReaderManagerConstructor, jsonReaderDataVariable, - _parentVisitor.Dependencies.LiftableConstantFactory.CreateLiftableConstant( - _queryLogger, - static c => c.Dependencies.QueryLogger, - "queryLogger", - typeof(IDiagnosticsLogger)))), + MakeMemberAccess(QueryCompilationContext.QueryContextParameter, QueryContextQueryLoggerProperty))), Call(jsonReaderManagerVariable, Utf8JsonReaderManagerMoveNextMethod), Call(jsonReaderManagerVariable, Utf8JsonReaderManagerCaptureStateMethod)));