Skip to content

Commit d0ed930

Browse files
Copilotrenemadsen
andcommitted
Remove preparatory JSON infrastructure and debug code
Co-authored-by: renemadsen <76994+renemadsen@users.noreply.github.com>
1 parent de360ce commit d0ed930

6 files changed

Lines changed: 3 additions & 301 deletions

File tree

src/EFCore.MySql/Metadata/Conventions/MySqlConventionSetBuilder.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,6 @@ public override ConventionSet CreateConventionSet()
4444
conventionSet.PropertyAddedConventions.Add(new ColumnCharSetAttributeConvention(Dependencies));
4545
conventionSet.PropertyAddedConventions.Add(new ColumnCollationAttributeConvention(Dependencies));
4646

47-
// Add JSON column convention to set store type for JSON-mapped complex properties
48-
var jsonColumnConvention = new MySqlJsonColumnConvention(Dependencies, RelationalDependencies);
49-
conventionSet.ComplexPropertyAddedConventions.Add(jsonColumnConvention);
50-
conventionSet.ComplexPropertyAnnotationChangedConventions.Add(jsonColumnConvention);
51-
conventionSet.ComplexTypeAnnotationChangedConventions.Add(jsonColumnConvention);
52-
5347
var valueGenerationConvention = new MySqlValueGenerationConvention(Dependencies, RelationalDependencies);
5448
ReplaceConvention(conventionSet.EntityTypeBaseTypeChangedConventions, valueGenerationConvention);
5549
ReplaceConvention(conventionSet.EntityTypeAnnotationChangedConventions, (RelationalValueGenerationConvention)valueGenerationConvention);

src/EFCore.MySql/Metadata/Conventions/MySqlJsonColumnConvention.cs

Lines changed: 0 additions & 118 deletions
This file was deleted.

src/EFCore.MySql/Metadata/Internal/MySqlAnnotationProvider.cs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -164,31 +164,6 @@ public override IEnumerable<IAnnotation> For(IColumn column, bool designTime)
164164
var table = StoreObjectIdentifier.Table(column.Table.Name, column.Table.Schema);
165165
var properties = column.PropertyMappings.Select(m => m.Property).ToArray();
166166

167-
// Check if this is a container column for a JSON-mapped complex property
168-
// Container columns don't have property mappings in the traditional sense
169-
if (column.PropertyMappings.Count == 0 && column.Name != null)
170-
{
171-
// This might be a container column for a complex property
172-
// Check if there's a complex property with this name that has JSON mapping
173-
var entityTypes = column.Table.EntityTypeMappings.Select(m => m.TypeBase as IEntityType).Where(e => e != null);
174-
foreach (var entityType in entityTypes)
175-
{
176-
foreach (var complexProperty in entityType.GetComplexProperties())
177-
{
178-
// Cast to IReadOnlyTypeBase to access GetContainerColumnName
179-
var containerColumnName = (complexProperty.ComplexType as IReadOnlyTypeBase)?.GetContainerColumnName();
180-
if (containerColumnName == column.Name && complexProperty.GetJsonPropertyName() != null)
181-
{
182-
// This is a JSON container column - set the column type to "json"
183-
yield return new Annotation(
184-
RelationalAnnotationNames.ColumnType,
185-
"json");
186-
yield break;
187-
}
188-
}
189-
}
190-
}
191-
192167
if (column.PropertyMappings.Where(
193168
m => (m.TableMapping.IsSharedTablePrincipal ?? true) &&
194169
m.TableMapping.TypeBase == m.Property.DeclaringType)

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

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Data.Common;
7-
using System.IO;
87
using System.Linq;
9-
using System.Linq.Expressions;
10-
using System.Reflection;
11-
using System.Text;
128
using JetBrains.Annotations;
139
using Microsoft.EntityFrameworkCore;
1410
using Microsoft.EntityFrameworkCore.ChangeTracking;
@@ -61,9 +57,6 @@ protected override RelationalTypeMapping Clone(bool? noBackslashEscapes = null,
6157

6258
public abstract class MySqlJsonTypeMapping : MySqlStringTypeMapping, IMySqlCSharpRuntimeAnnotationTypeMappingCodeGenerator
6359
{
64-
protected static readonly MethodInfo _getString
65-
= typeof(DbDataReader).GetRuntimeMethod(nameof(DbDataReader.GetString), new[] { typeof(int) });
66-
6760
public MySqlJsonTypeMapping(
6861
[NotNull] string storeType,
6962
[NotNull] Type clrType,
@@ -125,28 +118,6 @@ protected override void ConfigureParameter(DbParameter parameter)
125118
}
126119
}
127120

128-
/// <summary>
129-
/// Returns the method to be used for reading JSON values from the database.
130-
/// MySQL stores JSON as strings, so we use GetString instead of the default GetFieldValue&lt;T&gt;.
131-
/// </summary>
132-
public override MethodInfo GetDataReaderMethod()
133-
{
134-
Console.WriteLine($"[DEBUG] MySqlJsonTypeMapping.GetDataReaderMethod() called - ClrType: {ClrType.Name} - returning DbDataReader.GetString");
135-
return _getString;
136-
}
137-
138-
/// <summary>
139-
/// Customizes the data reader expression for JSON types.
140-
/// This is only used for regular JSON columns mapped to string properties.
141-
/// Complex JSON types use MySqlStructuralJsonTypeMapping instead.
142-
/// </summary>
143-
public override Expression CustomizeDataReaderExpression(Expression expression)
144-
{
145-
Console.WriteLine($"[DEBUG] MySqlJsonTypeMapping.CustomizeDataReaderExpression() called - ClrType: {ClrType.Name} - no conversion");
146-
// For regular JSON columns, no conversion needed - just return the string
147-
return base.CustomizeDataReaderExpression(expression);
148-
}
149-
150121
void IMySqlCSharpRuntimeAnnotationTypeMappingCodeGenerator.Create(
151122
CSharpRuntimeAnnotationCodeGeneratorParameters codeGeneratorParameters,
152123
CSharpRuntimeAnnotationCodeGeneratorDependencies codeGeneratorDependencies)

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

Lines changed: 0 additions & 97 deletions
This file was deleted.

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

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)