Skip to content

Commit 85a75a0

Browse files
Copilotrenemadsen
andcommitted
Debug: Add Console.WriteLine logging to track type mapping usage
Added debug logging to: - MySqlStructuralJsonTypeMapping: Constructor, Clone, GetDataReaderMethod, CustomizeDataReaderExpression - MySqlJsonTypeMapping: GetDataReaderMethod, CustomizeDataReaderExpression - MySqlTypeMappingSource: When JsonTypePlaceholder is detected and structural mapping is returned This will help diagnose whether the structural type mapping is being used correctly or if the SQL generation is still seeing different type mappings that break column projection. Co-authored-by: renemadsen <76994+renemadsen@users.noreply.github.com>
1 parent e68aced commit 85a75a0

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

src/EFCore.MySql/Storage/Internal/MySqlJsonTypeMapping.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ protected override void ConfigureParameter(DbParameter parameter)
130130
/// MySQL stores JSON as strings, so we use GetString instead of the default GetFieldValue&lt;T&gt;.
131131
/// </summary>
132132
public override MethodInfo GetDataReaderMethod()
133-
=> _getString;
133+
{
134+
Console.WriteLine($"[DEBUG] MySqlJsonTypeMapping.GetDataReaderMethod() called - ClrType: {ClrType.Name} - returning DbDataReader.GetString");
135+
return _getString;
136+
}
134137

135138
/// <summary>
136139
/// Customizes the data reader expression for JSON types.
@@ -139,6 +142,7 @@ public override MethodInfo GetDataReaderMethod()
139142
/// </summary>
140143
public override Expression CustomizeDataReaderExpression(Expression expression)
141144
{
145+
Console.WriteLine($"[DEBUG] MySqlJsonTypeMapping.CustomizeDataReaderExpression() called - ClrType: {ClrType.Name} - no conversion");
142146
// For regular JSON columns, no conversion needed - just return the string
143147
return base.CustomizeDataReaderExpression(expression);
144148
}

src/EFCore.MySql/Storage/Internal/MySqlStructuralJsonTypeMapping.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,23 @@ private static readonly MethodInfo _getStringMethod
2929
public MySqlStructuralJsonTypeMapping(string storeType)
3030
: base(storeType, typeof(JsonTypePlaceholder), System.Data.DbType.String)
3131
{
32+
Console.WriteLine($"[DEBUG] MySqlStructuralJsonTypeMapping created - StoreType: {storeType}, ClrType: JsonTypePlaceholder");
3233
}
3334

3435
protected MySqlStructuralJsonTypeMapping(RelationalTypeMappingParameters parameters)
3536
: base(parameters)
3637
{
38+
Console.WriteLine($"[DEBUG] MySqlStructuralJsonTypeMapping cloned - StoreType: {parameters.StoreType}");
3739
}
3840

3941
/// <summary>
4042
/// MySQL stores JSON as strings, so we read using GetString.
4143
/// </summary>
4244
public override MethodInfo GetDataReaderMethod()
43-
=> _getStringMethod;
45+
{
46+
Console.WriteLine("[DEBUG] MySqlStructuralJsonTypeMapping.GetDataReaderMethod() called - returning DbDataReader.GetString");
47+
return _getStringMethod;
48+
}
4449

4550
/// <summary>
4651
/// Converts the string read from MySQL to a MemoryStream for EF Core's JSON processing.
@@ -52,7 +57,10 @@ public static MemoryStream CreateUtf8Stream(string json)
5257
/// Customizes the data reader expression to convert string to MemoryStream.
5358
/// </summary>
5459
public override Expression CustomizeDataReaderExpression(Expression expression)
55-
=> Expression.Call(_createUtf8StreamMethod, expression);
60+
{
61+
Console.WriteLine("[DEBUG] MySqlStructuralJsonTypeMapping.CustomizeDataReaderExpression() called - converting string to MemoryStream");
62+
return Expression.Call(_createUtf8StreamMethod, expression);
63+
}
5664

5765
protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters parameters)
5866
=> new MySqlStructuralJsonTypeMapping(parameters);

src/EFCore.MySql/Storage/Internal/MySqlTypeMappingSource.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ private RelationalTypeMapping FindRawMapping(RelationalTypeMappingInfo mappingIn
327327
// when creating JSON columns for complex types/collections. Return our structural JSON mapping.
328328
if (clrType?.Name == "JsonTypePlaceholder" && storeTypeName.Equals("json", StringComparison.OrdinalIgnoreCase))
329329
{
330+
Console.WriteLine($"[DEBUG] MySqlTypeMappingSource: Detected JsonTypePlaceholder for JSON column - returning MySqlStructuralJsonTypeMapping");
330331
return _jsonStructural;
331332
}
332333

0 commit comments

Comments
 (0)