Skip to content

Commit c566c43

Browse files
Copilotrenemadsen
andcommitted
Add null-safe checks to JsonDataTypeEmulation property access in CAST logic
Co-authored-by: renemadsen <76994+renemadsen@users.noreply.github.com>
1 parent 997d73a commit c566c43

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/EFCore.MySql/Query/ExpressionVisitors/Internal/MySqlQuerySqlGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ protected override Expression VisitJsonScalar(JsonScalarExpression jsonScalarExp
516516
// MariaDB does not support CAST(... AS json), so skip the CAST entirely when JsonDataTypeEmulation is enabled.
517517
// MariaDB stores JSON as LONGTEXT, so no explicit cast is needed - the data is already in a compatible text format.
518518
// This prevents SQL syntax errors like "near 'json) IS NULL'" on MariaDB while maintaining correct NULL comparison semantics.
519-
if (castStoreType == "json" && _options.ServerVersion.Supports.JsonDataTypeEmulation)
519+
if (castStoreType == "json" && _options?.ServerVersion?.Supports?.JsonDataTypeEmulation == true)
520520
{
521521
castStoreType = null;
522522
}
@@ -729,7 +729,7 @@ private SqlUnaryExpression VisitConvert(SqlUnaryExpression sqlUnaryExpression)
729729
// MariaDB does not support CAST(... AS json) syntax, so skip the conversion entirely when JsonDataTypeEmulation is enabled.
730730
// MariaDB stores JSON as LONGTEXT, so no explicit cast is needed - comparisons work correctly without it.
731731
// This avoids SQL syntax errors on MariaDB while maintaining correct NULL and equality comparison semantics.
732-
if (castMapping == "json" && _options.ServerVersion.Supports.JsonDataTypeEmulation)
732+
if (castMapping == "json" && _options?.ServerVersion?.Supports?.JsonDataTypeEmulation == true)
733733
{
734734
// For MariaDB with JsonDataTypeEmulation, skip the CAST by returning early
735735
Visit(sqlUnaryExpression.Operand);

0 commit comments

Comments
 (0)