c6dfa7915b
- gestione LogCodImp - migrazione
134 lines
4.7 KiB
C#
134 lines
4.7 KiB
C#
using System;
|
|
using LiMan.DB.DBModels;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata;
|
|
using Microsoft.Extensions.Configuration;
|
|
using NLog;
|
|
|
|
#nullable disable
|
|
|
|
namespace LiMan.DB
|
|
{
|
|
public partial class LMDbContext : Microsoft.EntityFrameworkCore.DbContext
|
|
{
|
|
#region Private Fields
|
|
|
|
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
private IConfiguration _configuration;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Public Constructors
|
|
|
|
[Obsolete("This constructor should never be used directly, and is only needed to generate entityframework stuff. Connection string can be adapted as pleased.")]
|
|
public LMDbContext()
|
|
{
|
|
}
|
|
|
|
public LMDbContext(IConfiguration configuration)
|
|
{
|
|
_configuration = configuration;
|
|
}
|
|
|
|
public LMDbContext(DbContextOptions<LMDbContext> options) : base(options)
|
|
{
|
|
try
|
|
{
|
|
// se non ci fosse... crea o migra!
|
|
Database.Migrate();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error(exc, "Exception during context initialization 02");
|
|
}
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Properties
|
|
|
|
public virtual DbSet<ApplicativoModel> DbSetApp { get; set; }
|
|
public virtual DbSet<FileAttachModel> DbSetFileAttach { get; set; }
|
|
public virtual DbSet<InstallazioneModel> DbSetInst { get; set; }
|
|
public virtual DbSet<LicenzaModel> DbSetLicenze { get; set; }
|
|
public virtual DbSet<LogCallModel> DbSetLogCall { get; set; }
|
|
public virtual DbSet<LogCodImp> DbSetLogCodImp { get; set; }
|
|
public virtual DbSet<LogLicenzaModel> DbSetLogLicenze { get; set; }
|
|
public virtual DbSet<SubLicenzaModel> DbSetSubLicenze { get; set; }
|
|
public virtual DbSet<TicketModel> DbSetTicket { get; set; }
|
|
public virtual DbSet<StatsCallModel> DbSetStatCall { get; set; }
|
|
public virtual DbSet<AuthUserModel> DbSetUsers { get; set; }
|
|
public virtual DbSet<AuthRoleModel> DbSetRoles { get; set; }
|
|
public virtual DbSet<AuthClaimModel> DbSetClaims { get; set; }
|
|
public virtual DbSet<ReleaseModel> DbSetReleases { get; set; }
|
|
public virtual DbSet<EnrollRequestModel> DbSetEnrollReq { get; set; }
|
|
public virtual DbSet<InstalledReleasesModel> DbSetInstallRel { get; set; }
|
|
public virtual DbSet<InstalledReleasesHistoryModel> DbSetInstallRelHist { get; set; }
|
|
|
|
#endregion Public Properties
|
|
|
|
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
|
|
|
|
|
|
#region Protected Methods
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
{
|
|
if (!optionsBuilder.IsConfigured)
|
|
{
|
|
string connString = _configuration.GetConnectionString("LiMan.DB");
|
|
if (!string.IsNullOrEmpty(connString))
|
|
{
|
|
optionsBuilder.UseSqlServer(connString);
|
|
}
|
|
else
|
|
{
|
|
//optionsBuilder.UseSqlServer("Server=SQLSTEAM;Database=LiMan.DB;Trusted_Connection=True;");
|
|
optionsBuilder.UseSqlServer("Server=W2019-SQL-STEAM;Database=LiMan.DB;Trusted_Connection=True;");
|
|
//optionsBuilder.UseSqlServer("Server=W2019-SQL-STEAM;Database=LiMan.DB;User ID=sa;Password=keyhammer16;integrated security=False;MultipleActiveResultSets=True;App=LiMan.UI");
|
|
}
|
|
}
|
|
}
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
modelBuilder.HasAnnotation("Relational:Collation", "SQL_Latin1_General_CP1_CI_AS");
|
|
|
|
modelBuilder.Entity<LogCallModel>(entity =>
|
|
{
|
|
entity.HasKey(e => new { e.DataRif, e.CodInst, e.CodApp, e.TargetUrl });
|
|
});
|
|
|
|
|
|
modelBuilder.Entity<StatsCallModel>(entity =>
|
|
{
|
|
entity.HasKey(e => new { e.YearRef, e.CodInst, e.CodApp });
|
|
|
|
entity.ToView("v_StatsCall");
|
|
});
|
|
|
|
OnModelCreatingPartial(modelBuilder);
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Public Methods
|
|
|
|
public void DbForceMigrate()
|
|
{
|
|
try
|
|
{
|
|
// se non ci fosse... crea o migra!
|
|
Database.Migrate();
|
|
Log.Info("DbForceMigrate: done!");
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error(exc, "DbForceMigrate: Exception during context initialization 01");
|
|
}
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |