@@ -44,7 +44,8 @@ private static readonly ConstructorInfo JsonReaderDataConstructor
4444 = typeof ( JsonReaderData ) . GetConstructor ( new [ ] { typeof ( Stream ) } ) ! ;
4545
4646 private static readonly ConstructorInfo JsonReaderManagerConstructor
47- = typeof ( Utf8JsonReaderManager ) . GetConstructor ( new [ ] { typeof ( JsonReaderData ) } ) ! ;
47+ = typeof ( Utf8JsonReaderManager ) . GetConstructor (
48+ new [ ] { typeof ( JsonReaderData ) , typeof ( IDiagnosticsLogger < DbLoggerCategory . Query > ) } ) ! ;
4849
4950 private static readonly MethodInfo Utf8JsonReaderManagerMoveNextMethod
5051 = typeof ( Utf8JsonReaderManager ) . GetMethod ( nameof ( Utf8JsonReaderManager . MoveNext ) , Array . Empty < Type > ( ) ) ! ;
@@ -64,6 +65,12 @@ private static readonly MethodInfo Utf8JsonReaderTrySkipMethod
6465 private static readonly PropertyInfo Utf8JsonReaderTokenTypeProperty
6566 = typeof ( Utf8JsonReader ) . GetProperty ( nameof ( Utf8JsonReader . TokenType ) ) ! ;
6667
68+ private static readonly MethodInfo Utf8JsonReaderGetStringMethod
69+ = typeof ( Utf8JsonReader ) . GetMethod ( nameof ( Utf8JsonReader . GetString ) , Array . Empty < Type > ( ) ) ! ;
70+
71+ private static readonly MethodInfo EnumParseMethodInfo
72+ = typeof ( Enum ) . GetMethod ( nameof ( Enum . Parse ) , new [ ] { typeof ( Type ) , typeof ( string ) } ) ! ;
73+
6774 private readonly RelationalShapedQueryCompilingExpressionVisitor _parentVisitor ;
6875 private readonly ISet < string > ? _tags ;
6976 private readonly bool _isTracking ;
@@ -73,6 +80,7 @@ private static readonly PropertyInfo Utf8JsonReaderTokenTypeProperty
7380 private readonly bool _generateCommandCache ;
7481 private readonly ParameterExpression _resultCoordinatorParameter ;
7582 private readonly ParameterExpression ? _executionStrategyParameter ;
83+ private readonly IDiagnosticsLogger < DbLoggerCategory . Query > _queryLogger ;
7684
7785 /// <summary>
7886 /// States scoped to SelectExpression
@@ -154,6 +162,7 @@ public ShaperProcessingExpressionVisitor(
154162 bool indexMap )
155163 {
156164 _parentVisitor = parentVisitor ;
165+ _queryLogger = parentVisitor . QueryCompilationContext . Logger ;
157166 _resultCoordinatorParameter = Parameter (
158167 splitQuery ? typeof ( SplitQueryResultCoordinator ) : typeof ( SingleQueryResultCoordinator ) , "resultCoordinator" ) ;
159168 _executionStrategyParameter = splitQuery ? Parameter ( typeof ( IExecutionStrategy ) , "executionStrategy" ) : null ;
@@ -187,6 +196,7 @@ private ShaperProcessingExpressionVisitor(
187196 ReaderColumn ? [ ] ? readerColumns )
188197 {
189198 _parentVisitor = parentVisitor ;
199+ _queryLogger = parentVisitor . QueryCompilationContext . Logger ;
190200 _resultCoordinatorParameter = resultCoordinatorParameter ;
191201
192202 _selectExpression = selectExpression ;
@@ -209,6 +219,7 @@ private ShaperProcessingExpressionVisitor(
209219 ISet < string > tags )
210220 {
211221 _parentVisitor = parentVisitor ;
222+ _queryLogger = parentVisitor . QueryCompilationContext . Logger ;
212223 _resultCoordinatorParameter = resultCoordinatorParameter ;
213224 _executionStrategyParameter = executionStrategyParameter ;
214225
@@ -1295,7 +1306,9 @@ private Expression CreateJsonShapers(
12951306 entityShaperExpression . EntityType ,
12961307 _isTracking ,
12971308 jsonReaderDataShaperLambdaParameter ,
1298- innerShapersMap , innerFixupMap ) . Rewrite ( entityShaperMaterializer ) ;
1309+ innerShapersMap ,
1310+ innerFixupMap ,
1311+ _queryLogger ) . Rewrite ( entityShaperMaterializer ) ;
12991312
13001313 var entityShaperMaterializerVariable = Variable (
13011314 entityShaperMaterializer . Type ,
@@ -1413,6 +1426,7 @@ private sealed class JsonEntityMaterializerRewriter : ExpressionVisitor
14131426 private readonly ParameterExpression _jsonReaderDataParameter ;
14141427 private readonly IDictionary < string , Expression > _innerShapersMap ;
14151428 private readonly IDictionary < string , LambdaExpression > _innerFixupMap ;
1429+ private readonly IDiagnosticsLogger < DbLoggerCategory . Query > _queryLogger ;
14161430
14171431 private static readonly PropertyInfo JsonEncodedTextEncodedUtf8BytesProperty
14181432 = typeof ( JsonEncodedText ) . GetProperty ( nameof ( JsonEncodedText . EncodedUtf8Bytes ) ) ! ;
@@ -1426,13 +1440,15 @@ public JsonEntityMaterializerRewriter(
14261440 bool isTracking ,
14271441 ParameterExpression jsonReaderDataParameter ,
14281442 IDictionary < string , Expression > innerShapersMap ,
1429- IDictionary < string , LambdaExpression > innerFixupMap )
1443+ IDictionary < string , LambdaExpression > innerFixupMap ,
1444+ IDiagnosticsLogger < DbLoggerCategory . Query > queryLogger )
14301445 {
14311446 _entityType = entityType ;
14321447 _isTracking = isTracking ;
14331448 _jsonReaderDataParameter = jsonReaderDataParameter ;
14341449 _innerShapersMap = innerShapersMap ;
14351450 _innerFixupMap = innerFixupMap ;
1451+ _queryLogger = queryLogger ;
14361452 }
14371453
14381454 public BlockExpression Rewrite ( BlockExpression jsonEntityShaperMaterializer )
@@ -1501,7 +1517,8 @@ protected override Expression VisitSwitch(SwitchExpression switchExpression)
15011517 managerVariable ,
15021518 New (
15031519 JsonReaderManagerConstructor ,
1504- _jsonReaderDataParameter ) ) ,
1520+ _jsonReaderDataParameter ,
1521+ Constant ( _queryLogger ) ) ) ,
15051522 // tokenType = jsonReaderManager.CurrentReader.TokenType
15061523 Assign (
15071524 tokenTypeVariable ,
@@ -1657,7 +1674,8 @@ protected override Expression VisitSwitch(SwitchExpression switchExpression)
16571674 var moveNext = Call ( managerVariable , Utf8JsonReaderManagerMoveNextMethod ) ;
16581675 var captureState = Call ( managerVariable , Utf8JsonReaderManagerCaptureStateMethod ) ;
16591676 var assignment = Assign ( propertyVariable , innerShaperMapElement . Value ) ;
1660- var managerRecreation = Assign ( managerVariable , New ( JsonReaderManagerConstructor , _jsonReaderDataParameter ) ) ;
1677+ var managerRecreation = Assign (
1678+ managerVariable , New ( JsonReaderManagerConstructor , _jsonReaderDataParameter , Constant ( _queryLogger ) ) ) ;
16611679
16621680 readExpressions . Add (
16631681 Block (
@@ -2011,7 +2029,8 @@ private static IList<T> PopulateList<T>(IList<T> buffer, IList<T> target)
20112029 jsonReaderDataVariable ,
20122030 Default ( typeof ( JsonReaderData ) ) ) ,
20132031 Block (
2014- Assign ( jsonReaderManagerVariable , New ( JsonReaderManagerConstructor , jsonReaderDataVariable ) ) ,
2032+ Assign (
2033+ jsonReaderManagerVariable , New ( JsonReaderManagerConstructor , jsonReaderDataVariable , Constant ( _queryLogger ) ) ) ,
20152034 Call ( jsonReaderManagerVariable , Utf8JsonReaderManagerMoveNextMethod ) ,
20162035 Call ( jsonReaderManagerVariable , Utf8JsonReaderManagerCaptureStateMethod ) ) ) ;
20172036
@@ -2373,7 +2392,6 @@ private Expression CreateReadJsonPropertyValueExpression(
23732392 {
23742393 // in case of null value we can't just use the JsonReader method, but rather check the current token type
23752394 // if it's JsonTokenType.Null means value is null, only if it's not we are safe to read the value
2376-
23772395 if ( resultExpression . Type != property . ClrType )
23782396 {
23792397 resultExpression = Convert ( resultExpression , property . ClrType ) ;
0 commit comments