Add JSON function to models
This commit is contained in:
7
DataAccess/EF_Demo/Data/DbJson.cs
Normal file
7
DataAccess/EF_Demo/Data/DbJson.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace EF_Demo.Data;
|
||||
|
||||
internal static class DbJson
|
||||
{
|
||||
public static string? JsonValue(string? expression, string path)
|
||||
=> throw new NotSupportedException();
|
||||
}
|
||||
14
DataAccess/EF_Demo/Data/MSSQL/EventsContext.Custom.cs
Normal file
14
DataAccess/EF_Demo/Data/MSSQL/EventsContext.Custom.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
14
DataAccess/EF_Demo/Data/Postgres/EventsContext.Custom.cs
Normal file
14
DataAccess/EF_Demo/Data/Postgres/EventsContext.Custom.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user