Add JSON function to models
This commit is contained in:
@@ -5,6 +5,7 @@ using EF_Demo.Data.MSSQL;
|
||||
#endif
|
||||
|
||||
using EF_Demo.Models;
|
||||
using EF_Demo.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
@@ -86,6 +87,12 @@ internal class Demo(IDbContextFactory<EventsContext> contextFactory, ILogger<Dem
|
||||
/// </summary>
|
||||
internal void PrintPeople(int year)
|
||||
{
|
||||
#if POSTGRES
|
||||
const string hrPath = "hr";
|
||||
#else
|
||||
const string hrPath = "$.hr";
|
||||
#endif
|
||||
|
||||
using var ctx = contextFactory.CreateDbContext();
|
||||
var query = ctx.People
|
||||
.Where(p => p.BirthDate.Year == year)
|
||||
@@ -97,11 +104,12 @@ internal class Demo(IDbContextFactory<EventsContext> contextFactory, ILogger<Dem
|
||||
p.FirstName, p.LastName,
|
||||
p.FirstNameTranscription, p.LastNameTranscription,
|
||||
p.BirthDate,
|
||||
Country = p.CountryCodeNavigation.Name
|
||||
Country = p.CountryCodeNavigation.Name,
|
||||
CountryHr = DbJson.JsonValue(p.CountryCodeNavigation.Translations, hrPath)
|
||||
});
|
||||
foreach (var p in query)
|
||||
{
|
||||
Console.WriteLine($"{p.FirstName} {p.LastName} ({p.FirstNameTranscription} {p.LastNameTranscription}), {p.Country} {p.BirthDate:dd.MM.yyyy.}");
|
||||
Console.WriteLine($"{p.FirstName} {p.LastName} ({p.FirstNameTranscription} {p.LastNameTranscription}), {p.Country} / {p.CountryHr} {p.BirthDate:dd.MM.yyyy.}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user