From cec933401defa2d68fba4abd7b27f5d71a52be2c Mon Sep 17 00:00:00 2001 From: Tobias Laving Date: Thu, 28 Aug 2025 10:20:13 +0200 Subject: [PATCH] Do not force json We are using scaffolding to create our database classes. Sadly, the scaffold does not support json on the json field, instead opting for string. This change will let the user use JSON functions more freely --- .../Internal/MySqlJsonDbFunctionsTranslator.cs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/EFCore.MySql/Query/ExpressionTranslators/Internal/MySqlJsonDbFunctionsTranslator.cs b/src/EFCore.MySql/Query/ExpressionTranslators/Internal/MySqlJsonDbFunctionsTranslator.cs index 09ca9ef84..a29ed4ad7 100644 --- a/src/EFCore.MySql/Query/ExpressionTranslators/Internal/MySqlJsonDbFunctionsTranslator.cs +++ b/src/EFCore.MySql/Query/ExpressionTranslators/Internal/MySqlJsonDbFunctionsTranslator.cs @@ -145,13 +145,7 @@ public virtual SqlExpression Translate( return result; - SqlExpression Json(SqlExpression e) => _sqlExpressionFactory.ApplyTypeMapping(EnsureJson(e), _sqlExpressionFactory.FindMapping(e.Type, "json")); - - static SqlExpression EnsureJson(SqlExpression e) - => e.TypeMapping is MySqlJsonTypeMapping || - e is MySqlJsonTraversalExpression - ? e - : throw new InvalidOperationException("The JSON method requires a JSON parameter but none was found."); + SqlExpression Json(SqlExpression e) => _sqlExpressionFactory.ApplyTypeMapping(e, _sqlExpressionFactory.FindMapping(e.Type, "json")); static SqlExpression RemoveConvert(SqlExpression e) {