Skip to content

Commit 810c8d4

Browse files
Copilotrenemadsen
andcommitted
Debug: Add diagnostic logging to JSON type mappings
Added Console.WriteLine statements to track: - When MySqlComplexJsonTypeMapping is created/cloned - When GetDataReaderMethod() is called - When CustomizeDataReaderExpression() is called and what conversions happen - When MySqlTypeMappingSource returns complex vs regular JSON mappings This will help diagnose the SQL syntax errors in bulk update scenarios. Co-authored-by: renemadsen <76994+renemadsen@users.noreply.github.com>
1 parent ab1143d commit 810c8d4

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public MySqlComplexJsonTypeMapping(
3333
bool replaceLineBreaksWithCharFunction)
3434
: base(storeType, valueConverter, valueComparer, noBackslashEscapes, replaceLineBreaksWithCharFunction)
3535
{
36+
Console.WriteLine($"[DEBUG] MySqlComplexJsonTypeMapping constructor called - StoreType: {storeType}, Converter: {valueConverter?.GetType().Name ?? "null"}");
3637
}
3738

3839
protected MySqlComplexJsonTypeMapping(
@@ -42,30 +43,42 @@ protected MySqlComplexJsonTypeMapping(
4243
bool replaceLineBreaksWithCharFunction)
4344
: base(parameters, mySqlDbType, noBackslashEscapes, replaceLineBreaksWithCharFunction)
4445
{
46+
Console.WriteLine($"[DEBUG] MySqlComplexJsonTypeMapping protected constructor called - ClrType: {ClrType?.Name ?? "null"}, StoreType: {StoreType}");
4547
}
4648

4749
protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters parameters)
48-
=> new MySqlComplexJsonTypeMapping(parameters, MySqlDbType, NoBackslashEscapes, ReplaceLineBreaksWithCharFunction);
50+
{
51+
Console.WriteLine($"[DEBUG] MySqlComplexJsonTypeMapping.Clone(parameters) called - ClrType: {parameters.CoreParameters.ClrType?.Name ?? "null"}");
52+
return new MySqlComplexJsonTypeMapping(parameters, MySqlDbType, NoBackslashEscapes, ReplaceLineBreaksWithCharFunction);
53+
}
4954

5055
protected override RelationalTypeMapping Clone(bool? noBackslashEscapes = null, bool? replaceLineBreaksWithCharFunction = null)
51-
=> new MySqlComplexJsonTypeMapping(
56+
{
57+
Console.WriteLine($"[DEBUG] MySqlComplexJsonTypeMapping.Clone(bool) called - ClrType: {ClrType?.Name ?? "null"}, StoreType: {StoreType}");
58+
return new MySqlComplexJsonTypeMapping(
5259
Parameters,
5360
MySqlDbType,
5461
noBackslashEscapes ?? NoBackslashEscapes,
5562
replaceLineBreaksWithCharFunction ?? ReplaceLineBreaksWithCharFunction);
63+
}
5664

5765
/// <summary>
5866
/// Returns the method to be used for reading JSON values from the database.
5967
/// MySQL stores JSON as strings, so we use GetString.
6068
/// </summary>
6169
public override MethodInfo GetDataReaderMethod()
62-
=> _getString;
70+
{
71+
Console.WriteLine($"[DEBUG] MySqlComplexJsonTypeMapping.GetDataReaderMethod() called - ClrType: {ClrType?.Name ?? "null"}, returning: {_getString?.Name ?? "null"}");
72+
return _getString;
73+
}
6374

6475
/// <summary>
6576
/// For complex JSON, we ALWAYS convert string to MemoryStream.
6677
/// </summary>
6778
public override Expression CustomizeDataReaderExpression(Expression expression)
6879
{
80+
Console.WriteLine($"[DEBUG] MySqlComplexJsonTypeMapping.CustomizeDataReaderExpression() called - ExpressionType: {expression.Type?.Name ?? "null"}, ClrType: {ClrType?.Name ?? "null"}");
81+
6982
if (expression.Type == typeof(string))
7083
{
7184
// Validate that reflection lookups succeeded (using cached members from base class)
@@ -75,6 +88,8 @@ public override Expression CustomizeDataReaderExpression(Expression expression)
7588
"Failed to find required reflection members for JSON type mapping.");
7689
}
7790

91+
Console.WriteLine($"[DEBUG] MySqlComplexJsonTypeMapping: Converting string expression to MemoryStream");
92+
7893
// Convert string to MemoryStream: new MemoryStream(Encoding.UTF8.GetBytes(stringValue))
7994
return Expression.New(
8095
_memoryStreamCtor,
@@ -84,6 +99,7 @@ public override Expression CustomizeDataReaderExpression(Expression expression)
8499
expression));
85100
}
86101

102+
Console.WriteLine($"[DEBUG] MySqlComplexJsonTypeMapping: No conversion, calling base.CustomizeDataReaderExpression");
87103
return base.CustomizeDataReaderExpression(expression);
88104
}
89105
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ private RelationalTypeMapping FindRawMapping(RelationalTypeMappingInfo mappingIn
326326
// when creating JSON columns for complex types/collections. Return our complex JSON mapping.
327327
if (clrType?.Name == "JsonTypePlaceholder" && storeTypeName.Equals("json", StringComparison.OrdinalIgnoreCase))
328328
{
329+
Console.WriteLine($"[DEBUG] MySqlTypeMappingSource: Detected JsonTypePlaceholder, returning _jsonComplexType");
329330
return _jsonComplexType;
330331
}
331332

@@ -349,6 +350,7 @@ private RelationalTypeMapping FindRawMapping(RelationalTypeMappingInfo mappingIn
349350
// Works for both MySQL (native JSON type) and MariaDB (JSON alias for LONGTEXT)
350351
if (storeTypeName.Equals("json", StringComparison.OrdinalIgnoreCase))
351352
{
353+
Console.WriteLine($"[DEBUG] MySqlTypeMappingSource: JSON store type with CLR type: {clrType?.Name ?? "null"}, returning _jsonDefaultString");
352354
// Return JSON mapping for any CLR type since JSON can serialize any object
353355
// The "json" store type works for both:
354356
// - MySQL 5.7.8+: Creates native JSON column with binary storage

0 commit comments

Comments
 (0)