Files
2021-10-08 18:15:49 +02:00

264 lines
8.4 KiB
C#

using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.Extensions.Configuration;
using NLog;
#nullable disable
namespace LiMan.GLS.DatabaseModels
{
public partial class LicManContext : 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 LicManContext()
{
}
public LicManContext(IConfiguration configuration)
{
_configuration = configuration;
}
public LicManContext(DbContextOptions<LicManContext> 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<AnagApplicazioni> DbSetApplicazioni { get; set; }
public virtual DbSet<AnagInstallazioni> DbSetInstallazioni { get; set; }
public virtual DbSet<LicenzeAttive> DbSetLicenzeAttive { get; set; }
public virtual DbSet<Permessi> DbSetPermessi { get; set; }
public virtual DbSet<Permessi2Funzione> DbSetPermessi2Funzione { get; set; }
#endregion Public Properties
#region Private Methods
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
#endregion Private Methods
#region Protected Methods
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
string connString = _configuration.GetConnectionString("LiMan.GLS");
if (!string.IsNullOrEmpty(connString))
{
optionsBuilder.UseSqlServer(connString);
}
else
{
optionsBuilder.UseSqlServer("Server=SQLSTEAM;Database=SteamWare_Auth;Trusted_Connection=True;");
}
}
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasAnnotation("Relational:Collation", "SQL_Latin1_General_CP1_CI_AS");
modelBuilder.Entity<AnagApplicazioni>(entity =>
{
entity.HasKey(e => e.Applicativo);
entity.ToTable("AnagApplicazioni");
entity.Property(e => e.Applicativo)
.HasMaxLength(50)
.HasColumnName("applicativo");
entity.Property(e => e.Descrizione)
.HasMaxLength(50)
.HasColumnName("descrizione");
});
modelBuilder.Entity<AnagInstallazioni>(entity =>
{
entity.HasKey(e => e.Installazione);
entity.ToTable("AnagInstallazioni");
entity.Property(e => e.Installazione)
.HasMaxLength(50)
.HasColumnName("installazione");
entity.Property(e => e.Contatto)
.HasMaxLength(50)
.HasColumnName("contatto");
entity.Property(e => e.Descrizione)
.HasMaxLength(50)
.HasColumnName("descrizione");
entity.Property(e => e.Email)
.HasMaxLength(50)
.HasColumnName("email");
});
modelBuilder.Entity<LicenzeAttive>(entity =>
{
entity.HasKey(e => e.IdxLic)
.HasName("PK_AnagKeyValue");
entity.ToTable("LicenzeAttive");
entity.Property(e => e.IdxLic).HasColumnName("idxLic");
entity.Property(e => e.Applicativo)
.HasMaxLength(50)
.HasColumnName("applicativo")
.HasDefaultValueSql("(N'-')");
entity.Property(e => e.Descrizione)
.HasMaxLength(250)
.HasColumnName("descrizione")
.HasDefaultValueSql("('-')");
entity.Property(e => e.Installazione)
.HasMaxLength(50)
.HasColumnName("installazione")
.HasDefaultValueSql("(N'SteamWare')");
entity.Property(e => e.Licenza)
.HasMaxLength(250)
.HasColumnName("licenza")
.HasDefaultValueSql("('')");
entity.Property(e => e.NumLicenze)
.HasColumnName("numLicenze")
.HasDefaultValueSql("((0))");
entity.Property(e => e.Scadenza)
.HasColumnType("date")
.HasColumnName("scadenza");
entity.Property(e => e.Locked)
.HasColumnType("bit")
.HasColumnName("locked")
.HasDefaultValueSql("((0))");
entity.HasOne(d => d.ApplicativoNavigation)
.WithMany(p => p.LicenzeAttives)
.HasForeignKey(d => d.Applicativo)
.HasConstraintName("FK_AnagKeyValue_AnagApplicazioni");
entity.HasOne(d => d.InstallazioneNavigation)
.WithMany(p => p.LicenzeAttives)
.HasForeignKey(d => d.Installazione)
.HasConstraintName("FK_AnagKeyValue_AnagInstallazioni");
});
modelBuilder.Entity<Permessi>(entity =>
{
entity.HasKey(e => e.CodPermesso);
entity.ToTable("Permessi");
entity.Property(e => e.CodPermesso)
.HasMaxLength(50)
.IsUnicode(false)
.HasColumnName("COD_PERMESSO");
entity.Property(e => e.Descrizione)
.HasMaxLength(50)
.IsUnicode(false)
.HasColumnName("DESCRIZIONE");
entity.Property(e => e.Gruppo).HasColumnName("GRUPPO");
entity.Property(e => e.Nome)
.HasMaxLength(50)
.IsUnicode(false)
.HasColumnName("NOME");
entity.Property(e => e.Numero).HasColumnName("NUMERO");
entity.Property(e => e.Url)
.IsRequired()
.HasMaxLength(250)
.IsUnicode(false)
.HasColumnName("URL");
});
modelBuilder.Entity<Permessi2Funzione>(entity =>
{
entity.HasKey(e => new { e.CodPermesso, e.CodFunzione });
entity.ToTable("Permessi2Funzione");
entity.Property(e => e.CodPermesso)
.HasMaxLength(50)
.IsUnicode(false)
.HasColumnName("COD_PERMESSO");
entity.Property(e => e.CodFunzione)
.HasMaxLength(31)
.HasColumnName("COD_FUNZIONE");
entity.Property(e => e.Readwrite)
.HasMaxLength(1)
.IsUnicode(false)
.HasColumnName("READWRITE")
.IsFixedLength(true);
entity.HasOne(d => d.CodPermessoNavigation)
.WithMany(p => p.Permessi2Funziones)
.HasForeignKey(d => d.CodPermesso)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_Permessi2Funzione_Permessi");
});
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
}
}