dbcontext con tabelle dinamiche
This commit is contained in:
parent
c5dfa2ef58
commit
a9e2888d07
@ -58,7 +58,6 @@ namespace ApiPolo.Controllers
|
|||||||
private readonly Service _service;
|
private readonly Service _service;
|
||||||
|
|
||||||
private readonly TokenDbContext? _tokens;
|
private readonly TokenDbContext? _tokens;
|
||||||
private readonly Maras_DbContext _Maras;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#region TECNICI
|
#region TECNICI
|
||||||
@ -532,8 +531,7 @@ namespace ApiPolo.Controllers
|
|||||||
ConfigurazioniDbContext config,
|
ConfigurazioniDbContext config,
|
||||||
ITenantDbContextFactory dbContextFactory,
|
ITenantDbContextFactory dbContextFactory,
|
||||||
Service service,
|
Service service,
|
||||||
TokenDbContext tokens,
|
TokenDbContext tokens
|
||||||
Maras_DbContext maras
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
#region tecnici
|
#region tecnici
|
||||||
@ -905,7 +903,6 @@ namespace ApiPolo.Controllers
|
|||||||
_service = service;
|
_service = service;
|
||||||
_config = config;
|
_config = config;
|
||||||
_tokens = tokens;
|
_tokens = tokens;
|
||||||
_Maras = maras;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#region TECNICI
|
#region TECNICI
|
||||||
|
|||||||
@ -8,6 +8,7 @@ namespace ApiPolo.Data
|
|||||||
public class TenantDbContext : DbContext,ITenantDbContext
|
public class TenantDbContext : DbContext,ITenantDbContext
|
||||||
{
|
{
|
||||||
private readonly string _connectionString;
|
private readonly string _connectionString;
|
||||||
|
private readonly string _tenantCode;
|
||||||
|
|
||||||
#region PROPERTIES
|
#region PROPERTIES
|
||||||
public DbSet<Caus_Rapp>? Causali { get; set; }
|
public DbSet<Caus_Rapp>? Causali { get; set; }
|
||||||
@ -66,6 +67,7 @@ namespace ApiPolo.Data
|
|||||||
: base(options)
|
: base(options)
|
||||||
{
|
{
|
||||||
// Fetch the connection string dynamically based on tenant
|
// Fetch the connection string dynamically based on tenant
|
||||||
|
_tenantCode = tenant;
|
||||||
_connectionString = configuration.GetConnectionString(tenant)
|
_connectionString = configuration.GetConnectionString(tenant)
|
||||||
?? throw new KeyNotFoundException($"No connection string found for tenant: {tenant}");
|
?? throw new KeyNotFoundException($"No connection string found for tenant: {tenant}");
|
||||||
}
|
}
|
||||||
@ -126,14 +128,14 @@ namespace ApiPolo.Data
|
|||||||
|
|
||||||
TryConfigureEntity(mb =>
|
TryConfigureEntity(mb =>
|
||||||
{
|
{
|
||||||
mb.Entity<Compo_Impia_Table>().ToTable("DISCOMICOMIMP");
|
mb.Entity<Compo_Impia_Table>().ToTable($"{_tenantCode}MICOMIMP");
|
||||||
mb.Entity<Compo_Impia_Table>().HasKey(table => new
|
mb.Entity<Compo_Impia_Table>().HasKey(table => new
|
||||||
{
|
{
|
||||||
table.cocodimp,
|
table.cocodimp,
|
||||||
table.cprownum,
|
table.cprownum,
|
||||||
table.cocodazi
|
table.cocodazi
|
||||||
});
|
});
|
||||||
}, "DISCOMICOMIMP");
|
}, $"{_tenantCode}MICOMIMP");
|
||||||
|
|
||||||
TryConfigureEntity(mb => mb.Entity<Compo_Impia>().ToView("API_MICOMIMP"), "API_MICOMIMP");
|
TryConfigureEntity(mb => mb.Entity<Compo_Impia>().ToView("API_MICOMIMP"), "API_MICOMIMP");
|
||||||
|
|
||||||
@ -141,15 +143,15 @@ namespace ApiPolo.Data
|
|||||||
|
|
||||||
TryConfigureEntity(mb =>
|
TryConfigureEntity(mb =>
|
||||||
{
|
{
|
||||||
mb.Entity<Mag_New>().ToTable("DISCOMAG_NEW");
|
mb.Entity<Mag_New>().ToTable($"{_tenantCode}MAG_NEW");
|
||||||
mb.Entity<Mag_New>().HasKey(table => new
|
mb.Entity<Mag_New>().HasKey(table => new
|
||||||
{
|
{
|
||||||
table.seriale_rapportino,
|
table.seriale_rapportino,
|
||||||
table.riga
|
table.riga
|
||||||
});
|
});
|
||||||
}, "DISCOMAG_NEW");
|
}, $"{_tenantCode}MAG_NEW");
|
||||||
|
|
||||||
TryConfigureEntity(mb => mb.Entity<Magazzini>().ToTable("DISCOMAGAZZIN"), "DISCOMAGAZZIN");
|
TryConfigureEntity(mb =>mb.Entity<Magazzini>().ToTable($"{_tenantCode}MAGAZZIN"), $"{_tenantCode}MAGAZZIN");
|
||||||
|
|
||||||
TryConfigureEntity(mb => mb.Entity<Manprog>().ToView("API_MANPROG"), "API_MANPROG");
|
TryConfigureEntity(mb => mb.Entity<Manprog>().ToView("API_MANPROG"), "API_MANPROG");
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user