147 lines
4.6 KiB
C#
147 lines
4.6 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using MP.AppAuth.Models;
|
|
using NLog;
|
|
using System;
|
|
|
|
namespace MP.AppAuth
|
|
{
|
|
public partial class AppAuthContext : 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 AppAuthContext()
|
|
{
|
|
}
|
|
|
|
public AppAuthContext(IConfiguration configuration)
|
|
{
|
|
_configuration = configuration;
|
|
try
|
|
{
|
|
// se non ci fosse... crea o migra!
|
|
Database.Migrate();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error(exc, "Exception during context initialization 01");
|
|
}
|
|
}
|
|
|
|
public AppAuthContext(DbContextOptions<AppAuthContext> 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<AnagraficaGruppi> DbSetAnagraficaGruppi { get; set; }
|
|
public virtual DbSet<AnagraficaOperatori> DbSetAnagOpr { get; set; }
|
|
public virtual DbSet<Gruppi2Operatori> DbSetGruppi2Oper { get; set; }
|
|
public virtual DbSet<UpdMan> DbSetUpdMan { get; set; }
|
|
public virtual DbSet<Vocabolario> DbSetVocabolario { 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.Land");
|
|
if (!string.IsNullOrEmpty(connString))
|
|
{
|
|
optionsBuilder.UseSqlServer(connString);
|
|
}
|
|
else
|
|
{
|
|
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<Vocabolario>(entity =>
|
|
{
|
|
entity.HasKey(e => new { e.Lingua, e.Lemma });
|
|
|
|
entity.ToTable("Vocabolario");
|
|
|
|
entity.Property(e => e.Lingua).HasMaxLength(3);
|
|
|
|
entity.Property(e => e.Lemma).HasMaxLength(50);
|
|
|
|
entity.Property(e => e.Traduzione)
|
|
.IsRequired()
|
|
.HasMaxLength(500);
|
|
});
|
|
|
|
modelBuilder.Entity<AnagraficaGruppi>(entity =>
|
|
{
|
|
entity.HasKey(e => e.CodGruppo);
|
|
|
|
entity.ToTable("AnagraficaGruppi");
|
|
|
|
entity.Property(e => e.CodGruppo).HasMaxLength(50);
|
|
|
|
entity.Property(e => e.DescrGruppo)
|
|
.IsRequired()
|
|
.HasMaxLength(250)
|
|
.HasDefaultValueSql("('')");
|
|
|
|
entity.Property(e => e.SelEnabled).HasComment("Indica se sia selezionabile a livello di tendina x inserimento BCode");
|
|
|
|
entity.Property(e => e.TipoGruppo)
|
|
.IsRequired()
|
|
.HasMaxLength(50)
|
|
.HasDefaultValueSql("('REPARTO')")
|
|
.HasComment("tipo gruppo: reparto (es x gestione operatori assegnati), GRUPPO FASE (es macchien che fanno lo stesso tipo di lavoro), ...");
|
|
});
|
|
|
|
modelBuilder.Entity<Gruppi2Operatori>(entity =>
|
|
{
|
|
entity.HasKey(e => new { e.MatrOpr, e.CodGruppo });
|
|
|
|
entity.ToTable("Gruppi2Operatori");
|
|
|
|
entity.Property(e => e.CodGruppo).HasMaxLength(50);
|
|
});
|
|
|
|
//
|
|
modelBuilder.Seed();
|
|
|
|
OnModelCreatingPartial(modelBuilder);
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
}
|
|
} |