Add JSON function to models

This commit is contained in:
Boris Milašinović
2026-04-22 22:49:47 +02:00
parent 087293f67e
commit 3e38889ada
5 changed files with 69 additions and 2 deletions

View File

@@ -0,0 +1,7 @@
namespace EF_Demo.Data;
internal static class DbJson
{
public static string? JsonValue(string? expression, string path)
=> throw new NotSupportedException();
}

View File

@@ -0,0 +1,14 @@
using Microsoft.EntityFrameworkCore;
namespace EF_Demo.Data.MSSQL;
public partial class EventsContext
{
partial void OnModelCreatingPartial(ModelBuilder modelBuilder)
{
modelBuilder
.HasDbFunction(typeof(DbJson).GetMethod(nameof(DbJson.JsonValue))!)
.HasName("JSON_VALUE")
.IsBuiltIn();
}
}

View File

@@ -0,0 +1,14 @@
using Microsoft.EntityFrameworkCore;
namespace EF_Demo.Data.Postgres;
public partial class EventsContext
{
partial void OnModelCreatingPartial(ModelBuilder modelBuilder)
{
modelBuilder
.HasDbFunction(typeof(DbJson).GetMethod(nameof(DbJson.JsonValue))!)
.HasName("jsonb_extract_path_text")
.IsBuiltIn();
}
}