This commit is contained in:
2026-04-24 00:33:07 +03:30
parent 2f70fb0fef
commit 37e537f385
2 changed files with 42 additions and 25 deletions
+27 -11
View File
@@ -1,12 +1,14 @@
using Microsoft.EntityFrameworkCore;
using xDataService.Configuration;
namespace xDataService.Db {
namespace xDataService.Db
{
/// <summary>
/// Provide an abstraction layout arround DBContext ...
/// Only Used on EFCore ...
/// </summary>
public abstract class XDbContext : DbContext {
public abstract class XDbContext : DbContext
{
private readonly XDataServiceConfiguration config;
//
@@ -20,22 +22,30 @@ namespace xDataService.Db {
public XDbContext(
DbContextOptions options,
XDataServiceConfiguration config
) : base (options) {
) : base(options)
{
//
try {
try
{
Database.EnsureCreated();
Database.Migrate();
} catch { }
}
catch { }
this.config = config;
}
//
// Prepare Fluent API ...
protected override void OnModelCreating (ModelBuilder modelBuilder) {
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
//
OnXModelCreating(modelBuilder);
//
// Automatically apply all IEntityTypeConfiguration<T> in this assembly
modelBuilder.ApplyConfigurationsFromAssembly(typeof(XDbContext).Assembly);
//
// Since this class inherit from Identity Db Context,
// we have to pass this to Building Identity Models ...
@@ -47,21 +57,27 @@ namespace xDataService.Db {
//
// Prepare Configuring ...
protected override void OnConfiguring (DbContextOptionsBuilder optionsBuilder) {
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
//
if (config.EnableDetailedErrors) {
if (config.EnableDetailedErrors)
{
optionsBuilder.EnableDetailedErrors();
}
//
if (config.EnableSensitiveDataLogging) {
if (config.EnableSensitiveDataLogging)
{
optionsBuilder.EnableSensitiveDataLogging();
}
//
if (config.EnableTracking) {
if (config.EnableTracking)
{
optionsBuilder.UseQueryTrackingBehavior(QueryTrackingBehavior.TrackAll);
} else {
}
else
{
optionsBuilder.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
}
+2 -1
View File
@@ -27,7 +27,8 @@
<!-- Local Dependencies -->
<ItemGroup>
<ProjectReference Include="../xModels/xModels.csproj" />
<!-- <ProjectReference Include="../xModels/xModels.csproj" /> -->
<PackageReference Include="xDashboard.xModels" Version="1.0.0" />
</ItemGroup>
<!-- Dependencies -->