using System; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.Extensions.Configuration; using MP.Data.DatabaseModels; using NLog; #nullable disable // // This is here so CodeMaid doesn't reorganize this document // namespace MP.Data { public partial class MoonProContext : DbContext { #region Private Fields private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); private IConfiguration _configuration; #endregion Private Fields #region Public Constructors public MoonProContext(IConfiguration configuration) { _configuration = configuration; } public MoonProContext(DbContextOptions options) : base(options) { } #endregion Public Constructors #region Public Properties public virtual DbSet DbSetStatArticoli { get; set; } public virtual DbSet DbSetArticoli { get; set; } public virtual DbSet DbSetMacchine { get; set; } public virtual DbSet DbSetMSE { get; set; } public virtual DbSet DbSetConfig { get; set; } public virtual DbSet DbSetAnagGruppi { get; set; } public virtual DbSet DbSetListValues { get; set; } public virtual DbSet DbSetLinkMenu { get; set; } public virtual DbSet DbSetODL { get; set; } public virtual DbSet DbSetPODL { get; set; } public virtual DbSet DbSetFluxLog { get; set; } public virtual DbSet DbSetDossiers { get; set; } public virtual DbSet DbSetStatOdl { get; set; } public virtual DbSet DbSetStatoProd { get; set; } public virtual DbSet DbSetEvList { get; set; } public virtual DbSet DbSetVocabolario { get; set; } public virtual DbSet DbOperatori { 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("Mp.Data"); if (string.IsNullOrEmpty(connString)) { connString = _configuration.GetConnectionString("Mp.Mon"); } if (string.IsNullOrEmpty(connString)) { connString = _configuration.GetConnectionString("Mp.STATS"); } optionsBuilder.UseSqlServer(connString); //optionsBuilder.UseSqlServer("Server=SQL2016DEV;Database=MoonPro;Trusted_Connection=True;"); } } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.HasAnnotation("Relational:Collation", "SQL_Latin1_General_CP1_CI_AS"); modelBuilder.Entity(entity => { entity.HasKey(e => e.CodArticolo); entity.ToView("v_UI_AnagArticoli"); entity.Property(e => e.CodArticolo) .IsRequired() .HasMaxLength(50); entity.Property(e => e.DescArticolo) .IsRequired() .HasMaxLength(250); entity.Property(e => e.Disegno) .IsRequired() .HasMaxLength(50); entity.Property(e => e.Tipo) .IsRequired() .HasMaxLength(50); }); modelBuilder.Entity(entity => { entity.HasKey(e => e.CodArticolo); entity.ToView("AnagArticoli"); entity.Property(e => e.CodArticolo) .IsRequired() .HasMaxLength(50); entity.Property(e => e.DescArticolo) .IsRequired() .HasMaxLength(250); entity.Property(e => e.Disegno) .IsRequired() .HasMaxLength(50); entity.Property(e => e.Tipo) .IsRequired() .HasMaxLength(50); entity.Property(e => e.Azienda) .IsRequired() .HasMaxLength(50); }); modelBuilder.Entity(entity => { entity.HasKey(e => e.IdxMacchina); entity.ToView("Macchine"); entity.Property(e => e.CodMacchina).HasMaxLength(50); entity.Property(e => e.Descrizione).HasMaxLength(50); entity.Property(e => e.IdxMacchina) .IsRequired() .HasMaxLength(50); entity.Property(e => e.Nome).HasMaxLength(50); }); modelBuilder.Entity(entity => { entity.HasKey(e => e.RowNum); entity.ToTable("MappaStatoExpl"); entity.Property(e => e.CodArticolo) .HasMaxLength(50) .HasDefaultValueSql("('-')"); entity.Property(e => e.CodMacchina).HasMaxLength(50); entity.Property(e => e.DataInizioOdl) .HasColumnType("datetime") .HasColumnName("DataInizioODL"); entity.Property(e => e.DescrizioneStato) .HasMaxLength(50) .HasDefaultValueSql("('n.d.')"); entity.Property(e => e.Disegno) .HasMaxLength(50) .HasDefaultValueSql("('')"); entity.Property(e => e.Durata) .HasColumnName("durata") .HasDefaultValueSql("((0))"); entity.Property(e => e.IdxMacchina).HasMaxLength(50); entity.Property(e => e.IdxOdl).HasColumnName("idxODL"); entity.Property(e => e.IdxStato) .HasColumnName("idxStato") .HasDefaultValueSql("((0))"); entity.Property(e => e.LastUpdate) .HasColumnType("datetime") .HasColumnName("lastUpdate"); entity.Property(e => e.Nome).HasMaxLength(50); entity.Property(e => e.PezziConf).HasDefaultValueSql("((0))"); entity.Property(e => e.PezziProd).HasDefaultValueSql("((0))"); entity.Property(e => e.Semaforo) .HasMaxLength(50) .HasDefaultValueSql("('')"); entity.Property(e => e.TCAssegnato) .HasColumnType("decimal(18, 8)") .HasColumnName("TCAssegnato") .HasDefaultValueSql("((1))"); entity.Property(e => e.TCEff) .HasColumnType("decimal(18, 8)") .HasColumnName("TCEff") .HasDefaultValueSql("((0))"); entity.Property(e => e.TCEffRT) .HasColumnType("decimal(18, 8)") .HasColumnName("TCEffRT") .HasDefaultValueSql("((0))"); entity.Property(e => e.TCLav) .HasColumnType("decimal(18, 8)") .HasColumnName("TCLav") .HasDefaultValueSql("((0))"); entity.Property(e => e.TCLavRT) .HasColumnType("decimal(18, 8)") .HasColumnName("TCLavRT") .HasDefaultValueSql("((0))"); entity.Property(e => e.TCMedio) .HasColumnType("decimal(18, 8)") .HasColumnName("TCMedio") .HasDefaultValueSql("((0))"); entity.Property(e => e.TCMedioRt) .HasColumnType("decimal(18, 8)") .HasColumnName("TCMedioRT") .HasDefaultValueSql("((0))"); entity.Property(e => e.TempoAuto) .HasColumnType("decimal(18, 8)") .HasDefaultValueSql("((0))"); entity.Property(e => e.TempoOn) .HasColumnType("decimal(18, 8)") .HasDefaultValueSql("((0))"); entity.Property(e => e.TempoRun) .HasColumnType("decimal(18, 8)") .HasDefaultValueSql("((0))"); entity.Property(e => e.Url) .HasMaxLength(250) .HasColumnName("url"); }); modelBuilder.Entity(entity => { entity.HasKey(e => e.Chiave); entity.ToTable("Config"); entity.Property(e => e.Chiave) .HasMaxLength(50) .HasColumnName("chiave"); entity.Property(e => e.Note).HasColumnName("note"); entity.Property(e => e.Valore).HasColumnName("valore"); entity.Property(e => e.ValoreStd) .HasColumnName("valoreStd") .HasComment("Valore di default/riferimento per la variabile"); }); modelBuilder.Entity(entity => { entity.HasKey(e => e.CodGruppo); entity.Property(e => e.CodGruppo) .HasMaxLength(50) .HasColumnName("CodGruppo"); entity.Property(e => e.TipoGruppo) .HasMaxLength(50) .HasColumnName("TipoGruppo"); entity.Property(e => e.DescrGruppo) .HasMaxLength(250) .HasColumnName("DescrGruppo"); entity.Property(e => e.SelEnabled) .HasColumnName("SelEnabled"); }); modelBuilder.Entity(entity => { entity.HasKey(e => new { e.TableName, e.FieldName, e.value }); }); modelBuilder.Entity(entity => { entity.HasKey(e => new { e.IdxMacchina, e.dtEvento, e.CodFlux }); }); modelBuilder.Entity(entity => { entity.HasKey(e => new { e.IdxMacchina, e.InizioStato, e.IdxTipo }); }); modelBuilder.Entity(entity => { entity.HasKey(e => new { e.Lingua, e.Lemma }); }); OnModelCreatingPartial(modelBuilder); } #endregion Protected Methods } }