83 lines
2.7 KiB
C#
83 lines
2.7 KiB
C#
using Lux.Report.Data.DbModel;
|
|
|
|
namespace Lux.Report.Data
|
|
{
|
|
public partial class ReportContext : DbContext
|
|
{
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
private IConfiguration _configuration;
|
|
|
|
public ReportContext()
|
|
{
|
|
}
|
|
|
|
#if false
|
|
public ReportContext(IConfiguration configuration)
|
|
{
|
|
_configuration = configuration;
|
|
}
|
|
#endif
|
|
public ReportContext(DbContextOptions<ReportContext> options) : base(options)
|
|
{
|
|
try
|
|
{
|
|
// se non ci fosse... crea o migra!
|
|
Database.Migrate();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error(exc, "Exception during context initialization 02");
|
|
}
|
|
}
|
|
|
|
public virtual DbSet<ReportModel> DbSetReports { get; set; }
|
|
|
|
|
|
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
{
|
|
// default
|
|
string connString = DbConfig.CONNECTION_STRING;
|
|
if (string.IsNullOrEmpty(connString))
|
|
{
|
|
#if DEBUG
|
|
connString = "Server=mdb.ufficio;port=3306;database=Lux_000;uid=lux_user;pwd=Egal_pwd!;sslmode=None;";
|
|
//connString = "Server=mdb.ufficio;port=3306;database=Lux_000_dev;uid=lux_user;pwd=Egal_pwd!;sslmode=None;";
|
|
#else
|
|
connString = "Server=mdb.ufficio;port=3306;database=Lux_000;uid=lux_user;pwd=Egal_pwd!;sslmode=None;";
|
|
#endif
|
|
}
|
|
if (!optionsBuilder.IsConfigured)
|
|
{
|
|
var serverVersion = ServerVersion.AutoDetect(connString);
|
|
|
|
// 2026.01.09 aggiornata init componente POMELO
|
|
#if false
|
|
optionsBuilder.UseMySql(connString, serverVersion);
|
|
#endif
|
|
optionsBuilder.UseMySql(connString, serverVersion, options =>
|
|
{
|
|
// Questo abilita il supporto JSON specifico per MySQL
|
|
options.EnableStringComparisonTranslations();
|
|
});
|
|
// verificare setup componente
|
|
#if false
|
|
optionsBuilder
|
|
.UseMySql(connString, serverVersion)
|
|
.UseSnakeCaseNamingConvention(); // via EFCore.NamingConventions
|
|
#endif
|
|
}
|
|
}
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
foreach (var relationship in modelBuilder.Model.GetEntityTypes().SelectMany(e => e.GetForeignKeys()))
|
|
{
|
|
relationship.DeleteBehavior = DeleteBehavior.Restrict;
|
|
}
|
|
}
|
|
}
|
|
}
|