@@ -87,10 +87,8 @@ private readonly RelationalTypeMapping _binaryRowVersion6
8787 // guid
8888 private GuidTypeMapping _guid ;
8989
90- // JSON default mapping for regular JSON columns mapped to string
90+ // JSON default mapping
9191 private MySqlJsonTypeMapping < string > _jsonDefaultString ;
92- // JSON mapping for complex types (types mapped with .ToJson())
93- private MySqlStructuralJsonTypeMapping _jsonStructural ;
9492
9593 // Scaffolding type mappings
9694 private readonly MySqlCodeGenerationMemberAccessTypeMapping _codeGenerationMemberAccess = MySqlCodeGenerationMemberAccessTypeMapping . Default ;
@@ -137,7 +135,6 @@ private void Initialize()
137135 : null ;
138136
139137 _jsonDefaultString = new MySqlJsonTypeMapping < string > ( "json" , null , null , _options . NoBackslashEscapes , _options . ReplaceLineBreaksWithCharFunction ) ;
140- _jsonStructural = new MySqlStructuralJsonTypeMapping ( "json" ) ;
141138
142139 _storeTypeMappings
143140 = new Dictionary < string , RelationalTypeMapping [ ] > ( StringComparer . OrdinalIgnoreCase )
@@ -204,10 +201,6 @@ private void Initialize()
204201 { "time" , new RelationalTypeMapping [ ] { _timeTimeOnly , _timeTimeSpan } } ,
205202 { "datetime" , new RelationalTypeMapping [ ] { _dateTime , _dateTimeOffset } } ,
206203 { "timestamp" , new RelationalTypeMapping [ ] { _timeStamp , _timeStampOffset } } ,
207-
208- // json - for complex types mapped with .ToJson()
209- // This supports both MySQL 5.7.8+ (native JSON) and MariaDB 10.2.4+ (JSON as LONGTEXT alias)
210- { "json" , new [ ] { _jsonDefaultString } } ,
211204 } ;
212205
213206 _clrTypeMappings
@@ -312,15 +305,6 @@ private RelationalTypeMapping FindRawMapping(RelationalTypeMappingInfo mappingIn
312305 var storeTypeName = mappingInfo . StoreTypeName ;
313306 var storeTypeNameBase = mappingInfo . StoreTypeNameBase ;
314307
315- // Special case for JSON columns: EF Core passes JsonTypePlaceholder as the CLR type
316- // when creating JSON columns for complex types/collections. Return our structural JSON mapping.
317- // This MUST be checked first, before any store type lookups, similar to SQL Server's implementation.
318- if ( clrType ? . Name == "JsonTypePlaceholder" )
319- {
320- Console . WriteLine ( $ "[DEBUG] MySqlTypeMappingSource: Detected JsonTypePlaceholder - returning MySqlStructuralJsonTypeMapping") ;
321- return _jsonStructural ;
322- }
323-
324308 if ( storeTypeName != null )
325309 {
326310 // First look for the fully qualified store type name.
@@ -331,7 +315,6 @@ private RelationalTypeMapping FindRawMapping(RelationalTypeMappingInfo mappingIn
331315 // mapping as the default.
332316 // If a CLR type was provided, look for a mapping between the store and CLR types. If none is found,
333317 // fail immediately.
334-
335318 return clrType == null
336319 ? mappings [ 0 ]
337320 : mappings . FirstOrDefault ( m => m . ClrType == clrType ) ;
@@ -347,15 +330,9 @@ private RelationalTypeMapping FindRawMapping(RelationalTypeMappingInfo mappingIn
347330 ? . WithTypeMappingInfo ( in mappingInfo ) ;
348331 }
349332
350- // Handle JSON store type for any CLR type
351- // This is needed for complex collections mapped with .ToJson() in EF Core 10+
352- // Works for both MySQL (native JSON type) and MariaDB (JSON alias for LONGTEXT)
353- if ( storeTypeName . Equals ( "json" , StringComparison . OrdinalIgnoreCase ) )
333+ if ( storeTypeName . Equals ( "json" , StringComparison . OrdinalIgnoreCase ) &&
334+ ( clrType == null || clrType == typeof ( string ) || clrType == typeof ( MySqlJsonString ) ) )
354335 {
355- // Return JSON mapping for any CLR type since JSON can serialize any object
356- // The "json" store type works for both:
357- // - MySQL 5.7.8+: Creates native JSON column with binary storage
358- // - MariaDB 10.2.4+: Creates LONGTEXT column with JSON validation constraint
359336 return _jsonDefaultString ;
360337 }
361338
0 commit comments