Code: Select all
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json.Linq;
namespace Lib.Extensions
{
public static class EfExtensions
{
/// <summary>
/// JSON_VALUE function for EF
/// https://github.com/aspnet/EntityFrameworkCore/issues/11295#issuecomment-373852015
/// </summary>
public static string JsonValue(string column, [NotParameterized] string path)
{
// C# implementation, not important for the current issue
}
/// <summary>
/// Adds support for JSON_VALUE inside EF queries on this DB context
/// </summary>
/// <example>
/// query.Where(_ => _.Reference != null && EfExtensions.JsonValue(_.Reference, $"$.{key}") == value)
/// </example>
public static void AddJsonValue(ModelBuilder bld)
{
bld.HasDbFunction(typeof(EfExtensions).GetMethod(nameof(JsonValue)))
.HasName("JSON_VALUE")
.HasSchema("");
}
}
}
My problem is that it works on SQL Server, where EF generates this kind of SQL :
Code: Select all
WHERE (JSON_VALUE("_".REFERENCE, N'$.AffaireId') = @p__ToString_0))
Code: Select all
WHERE (JSON_VALUE("_".REFERENCE, $.AffaireId) = :p__ToString_0))
What am I missing ?