Skip to content

Commit 7d2dae1

Browse files
Copilotrenemadsen
andcommitted
Critical fix: Revert to dbType: null and add ClrType property override
KEY FINDING from Npgsql comparison: Must use `dbType: null` (not DbType.String)! Changes: 1. Reverted `dbType: System.Data.DbType.String` → `dbType: null` to match Npgsql exactly 2. Added explicit `ClrType` property override returning `typeof(JsonTypePlaceholder)` Npgsql's NpgsqlStructuralJsonTypeMapping uses dbType: null, which is critical for EF Core's SQL generator to properly handle JsonTypePlaceholder during column projection. Using DbType.String was causing the empty column issue. The explicit ClrType property override ensures the type is consistently returned as JsonTypePlaceholder, preventing EF Core from inferring different types. Co-authored-by: renemadsen <76994+renemadsen@users.noreply.github.com>
1 parent c9d31cb commit 7d2dae1

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ private static readonly ConstructorInfo _memoryStreamConstructor
3434
public static MySqlStructuralJsonTypeMapping Default { get; } = new("json");
3535

3636
public MySqlStructuralJsonTypeMapping(string storeType)
37-
: base(storeType, typeof(JsonTypePlaceholder), System.Data.DbType.String)
37+
: base(storeType, typeof(JsonTypePlaceholder), dbType: null)
3838
{
39-
Console.WriteLine($"[DEBUG] MySqlStructuralJsonTypeMapping created - StoreType: {storeType}, ClrType: JsonTypePlaceholder, DbType: String");
39+
Console.WriteLine($"[DEBUG] MySqlStructuralJsonTypeMapping created - StoreType: {storeType}, ClrType: JsonTypePlaceholder, DbType: null");
4040
}
4141

4242
protected MySqlStructuralJsonTypeMapping(RelationalTypeMappingParameters parameters)
@@ -72,6 +72,11 @@ public override Expression CustomizeDataReaderExpression(Expression expression)
7272
protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters parameters)
7373
=> new MySqlStructuralJsonTypeMapping(parameters);
7474

75+
/// <summary>
76+
/// Override to ensure we return JsonTypePlaceholder type consistently
77+
/// </summary>
78+
public override Type ClrType => typeof(JsonTypePlaceholder);
79+
7580
protected string EscapeSqlLiteral(string literal)
7681
=> literal.Replace("'", "''");
7782

0 commit comments

Comments
 (0)