How can I use SQL Server JSON_VALUE function in EF 6 Code First for classic .NET? I found I can do it in EF Core like this:
public static class JsonExtensions
{
public static string JsonValue(string column, [NotParameterized] string path)
{
throw new NotSupportedException();
}
}
// In OnModelCreating
modelBuilder.HasDbFunction(typeof(JsonExtensions).GetMethod(nameof(JsonExtensions.JsonValue)))
.HasName("JSON_VALUE")
.HasSchema("");
// And then the usage
var result = db.Blogs.Select(t => JsonExtensions.JsonValue(t.Log, "$.JsonPropertyName")).ToArray();
But how can I achieve this in EF 6 in classic .NET (in my case, its 4.6.1)?
In classic .NET it's a little bit different, but still possible like this:
Then, because JSON_VALUE is not defined in the Entity Framework SQL Server provider manifest, you have to create IStoreModelConvention like this: