last ...
This commit is contained in:
+40
-24
@@ -1,12 +1,14 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using xDataService.Configuration;
|
using xDataService.Configuration;
|
||||||
|
|
||||||
namespace xDataService.Db {
|
namespace xDataService.Db
|
||||||
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provide an abstraction layout arround DBContext ...
|
/// Provide an abstraction layout arround DBContext ...
|
||||||
/// Only Used on EFCore ...
|
/// Only Used on EFCore ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class XDbContext : DbContext {
|
public abstract class XDbContext : DbContext
|
||||||
|
{
|
||||||
private readonly XDataServiceConfiguration config;
|
private readonly XDataServiceConfiguration config;
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -17,62 +19,76 @@ namespace xDataService.Db {
|
|||||||
|
|
||||||
//
|
//
|
||||||
// Constructor ...
|
// Constructor ...
|
||||||
public XDbContext (
|
public XDbContext(
|
||||||
DbContextOptions options,
|
DbContextOptions options,
|
||||||
XDataServiceConfiguration config
|
XDataServiceConfiguration config
|
||||||
) : base (options) {
|
) : base(options)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
try {
|
try
|
||||||
Database.EnsureCreated ();
|
{
|
||||||
Database.Migrate ();
|
Database.EnsureCreated();
|
||||||
} catch { }
|
Database.Migrate();
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
|
||||||
this.config = config;
|
this.config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Prepare Fluent API ...
|
// Prepare Fluent API ...
|
||||||
protected override void OnModelCreating (ModelBuilder modelBuilder) {
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
OnXModelCreating (modelBuilder);
|
OnXModelCreating(modelBuilder);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Automatically apply all IEntityTypeConfiguration<T> in this assembly
|
||||||
|
modelBuilder.ApplyConfigurationsFromAssembly(typeof(XDbContext).Assembly);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Since this class inherit from Identity Db Context,
|
// Since this class inherit from Identity Db Context,
|
||||||
// we have to pass this to Building Identity Models ...
|
// we have to pass this to Building Identity Models ...
|
||||||
base.OnModelCreating (modelBuilder);
|
base.OnModelCreating(modelBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
public abstract void OnXModelCreating (ModelBuilder modelBuilder);
|
public abstract void OnXModelCreating(ModelBuilder modelBuilder);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Prepare Configuring ...
|
// Prepare Configuring ...
|
||||||
protected override void OnConfiguring (DbContextOptionsBuilder optionsBuilder) {
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
if (config.EnableDetailedErrors) {
|
if (config.EnableDetailedErrors)
|
||||||
optionsBuilder.EnableDetailedErrors ();
|
{
|
||||||
|
optionsBuilder.EnableDetailedErrors();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
if (config.EnableSensitiveDataLogging) {
|
if (config.EnableSensitiveDataLogging)
|
||||||
optionsBuilder.EnableSensitiveDataLogging ();
|
{
|
||||||
|
optionsBuilder.EnableSensitiveDataLogging();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
if (config.EnableTracking) {
|
if (config.EnableTracking)
|
||||||
optionsBuilder.UseQueryTrackingBehavior (QueryTrackingBehavior.TrackAll);
|
{
|
||||||
} else {
|
optionsBuilder.UseQueryTrackingBehavior(QueryTrackingBehavior.TrackAll);
|
||||||
optionsBuilder.UseQueryTrackingBehavior (QueryTrackingBehavior.NoTracking);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
optionsBuilder.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
OnXConfiguring (optionsBuilder);
|
OnXConfiguring(optionsBuilder);
|
||||||
|
|
||||||
//
|
//
|
||||||
base.OnConfiguring (optionsBuilder);
|
base.OnConfiguring(optionsBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
public abstract void OnXConfiguring (DbContextOptionsBuilder optionsBuilder);
|
public abstract void OnXConfiguring(DbContextOptionsBuilder optionsBuilder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2
-1
@@ -27,7 +27,8 @@
|
|||||||
|
|
||||||
<!-- Local Dependencies -->
|
<!-- Local Dependencies -->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="../xModels/xModels.csproj" />
|
<!-- <ProjectReference Include="../xModels/xModels.csproj" /> -->
|
||||||
|
<PackageReference Include="xDashboard.xModels" Version="1.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<!-- Dependencies -->
|
<!-- Dependencies -->
|
||||||
|
|||||||
Reference in New Issue
Block a user