Skip to content

Commit fdaec6c

Browse files
Copilotrenemadsen
andcommitted
Fix: Add GetDataReaderMethod override to MySqlComplexJsonTypeMapping
The MySqlComplexJsonTypeMapping was missing the GetDataReaderMethod() override, causing it to use the default behavior which led to SQL syntax errors. Added the override to return GetString for reading JSON as strings from MySQL. Also made _getString protected so it can be accessed by derived classes. Fixes SQL syntax error in ComplexJsonProjectionMySqlTest. Co-authored-by: renemadsen <76994+renemadsen@users.noreply.github.com>
1 parent c5d7693 commit fdaec6c

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ protected override RelationalTypeMapping Clone(bool? noBackslashEscapes = null,
5454
noBackslashEscapes ?? NoBackslashEscapes,
5555
replaceLineBreaksWithCharFunction ?? ReplaceLineBreaksWithCharFunction);
5656

57+
/// <summary>
58+
/// Returns the method to be used for reading JSON values from the database.
59+
/// MySQL stores JSON as strings, so we use GetString.
60+
/// </summary>
61+
public override MethodInfo GetDataReaderMethod()
62+
=> _getString;
63+
5764
/// <summary>
5865
/// For complex JSON, we ALWAYS convert string to MemoryStream.
5966
/// </summary>
@@ -127,7 +134,7 @@ protected override RelationalTypeMapping Clone(bool? noBackslashEscapes = null,
127134

128135
public abstract class MySqlJsonTypeMapping : MySqlStringTypeMapping, IMySqlCSharpRuntimeAnnotationTypeMappingCodeGenerator
129136
{
130-
private static readonly MethodInfo _getString
137+
protected static readonly MethodInfo _getString
131138
= typeof(DbDataReader).GetRuntimeMethod(nameof(DbDataReader.GetString), new[] { typeof(int) });
132139

133140
// Cache reflection lookups for performance

0 commit comments

Comments
 (0)