Inizio creazione modelli dati + migrazione iniziale

This commit is contained in:
Samuele Locatelli
2021-12-07 15:13:54 +01:00
parent 61c39aa3d5
commit 7c0c3f25b3
7 changed files with 494 additions and 1 deletions
+29
View File
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace GPW.CORE.Data.DbModels
{
// <Auto-Generated>
// This is here so CodeMaid doesn't reorganize this document
// </Auto-Generated>
[Table("CheckVc19")]
public partial class CheckVc19Model
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int IdxCheckVc19 { get; set; }
public DateTime DtCheck { get; set; } = DateTime.Now;
public int IdxDipendente { get; set; }
public string Cognome { get; set; } = null!;
public string Nome { get; set; } = null!;
public DateTime Dob { get; set; }
public string Payload { get; set; } = null!;
/// <summary>
/// Navigation property to Dipendente
/// </summary>
[ForeignKey("IdxDipendente")]
public virtual Dipendenti? DipNav { get; set; }
}
}
+52
View File
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
namespace GPW.CORE.Data.DbModels
{
public partial class Dipendenti
{
public Dipendenti()
{
RegAttivita = new HashSet<RegAttivitum>();
RilievoTemps = new HashSet<RilievoTemp>();
Timbratures = new HashSet<Timbrature>();
}
public int IdxDipendente { get; set; }
public string? Matricola { get; set; }
public string Cf { get; set; } = null!;
public string? Cognome { get; set; }
public string? Nome { get; set; }
public DateTime? DataNascita { get; set; }
public string? LuogoNascita { get; set; }
public string? ProvNascita { get; set; }
public string? NazNascita { get; set; }
public string CodHw { get; set; } = null!;
public string? CodOrario { get; set; }
public bool? MailLastOp { get; set; }
public bool? MailDay { get; set; }
public bool? MailWeek { get; set; }
public bool? MailMonth { get; set; }
public string Email { get; set; } = null!;
public string AuthKey { get; set; } = null!;
/// <summary>
/// numero di impieghi della authKey
/// </summary>
public int? NumAuth { get; set; }
public string? WolMac { get; set; }
public string Dominio { get; set; } = null!;
public string Utente { get; set; } = null!;
/// <summary>
/// nome/codice dipendente per sistema esterno da importare
/// </summary>
public string CodDipendenteExt { get; set; } = null!;
public string? Gruppo { get; set; }
public DateTime? DataAssunzione { get; set; }
public DateTime? DataCessazione { get; set; }
public bool? Attivo { get; set; }
public virtual ICollection<RegAttivitum> RegAttivita { get; set; }
public virtual ICollection<RilievoTemp> RilievoTemps { get; set; }
public virtual ICollection<Timbrature> Timbratures { get; set; }
}
}
+22
View File
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
namespace GPW.CORE.Data.DbModels
{
public partial class RegAttivitum
{
public int IdxRa { get; set; }
public int IdxDipendente { get; set; }
public int IdxFase { get; set; }
public DateTime Inizio { get; set; }
public DateTime Fine { get; set; }
public string? Descrizione { get; set; }
/// <summary>
/// Ore Attività - prima era ([dbo].[f_hourInterval]([inizio],[fine])) poi sostituita per performance
/// </summary>
public decimal? OreTot { get; set; }
public decimal? Importo { get; set; }
public virtual Dipendenti IdxDipendenteNavigation { get; set; } = null!;
}
}
+14
View File
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
namespace GPW.CORE.Data.DbModels
{
public partial class RilievoTemp
{
public int IdxDipendente { get; set; }
public DateTime DtRilievo { get; set; }
public decimal TempRil { get; set; }
public virtual Dipendenti IdxDipendenteNavigation { get; set; } = null!;
}
}
+20
View File
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
namespace GPW.CORE.Data.DbModels
{
public partial class Timbrature
{
public DateTime DataOra { get; set; }
public int IdxDipendente { get; set; }
public bool? Entrata { get; set; }
public string? Ipv4 { get; set; }
public string? CodTipoTimb { get; set; }
/// <summary>
/// Approvazioen timbratura (default true...)
/// </summary>
public bool? Approv { get; set; }
public virtual Dipendenti IdxDipendenteNavigation { get; set; } = null!;
}
}
+12 -1
View File
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
@@ -6,4 +6,15 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NLog" Version="4.7.13" />
</ItemGroup>
</Project>
+345
View File
@@ -0,0 +1,345 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.Extensions.Configuration;
using NLog;
namespace GPW.CORE.Data.DbModels
{
public partial class GPWContext : DbContext
{
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
private IConfiguration _configuration = null!;
public GPWContext()
{
}
public GPWContext(IConfiguration configuration)
{
_configuration = configuration;
}
public GPWContext(DbContextOptions<GPWContext> 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<CheckVc19> DbSetCheckVc19 { get; set; } = null!;
public virtual DbSet<Dipendenti> DbSetDipendenti { get; set; } = null!;
public virtual DbSet<RegAttivitum> DbSetRegAttivita { get; set; } = null!;
public virtual DbSet<RilievoTemp> DbSetRilievoTemp { get; set; } = null!;
public virtual DbSet<Timbrature> DbSetTimbrature { get; set; } = null!;
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
string connString = _configuration.GetConnectionString("NKC.DB");
if (!string.IsNullOrEmpty(connString))
{
optionsBuilder.UseSqlServer(connString);
}
else
{
optionsBuilder.UseSqlServer("Server=SQL2016DEV;Database=Sauder_NKC;Trusted_Connection=True;");
optionsBuilder.UseSqlServer("Server=SQLSTEAM;Database=GPW;Trusted_Connection=True;");
}
}
}
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");
}
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.UseCollation("Latin1_General_CI_AS");
modelBuilder.Entity<CheckVc19>(entity =>
{
entity.HasKey(e => e.IdxCheckVc19)
.HasName("PK_CheckC19");
entity.ToTable("CheckVC19");
entity.Property(e => e.Cognome)
.HasMaxLength(100)
.HasColumnName("cognome")
.HasDefaultValueSql("('')");
entity.Property(e => e.Dob)
.HasColumnType("datetime")
.HasColumnName("DOB")
.HasDefaultValueSql("(getdate())");
entity.Property(e => e.DtCheck)
.HasColumnType("datetime")
.HasColumnName("dtCheck")
.HasDefaultValueSql("(getdate())");
entity.Property(e => e.IdxDipendente).HasColumnName("idxDipendente");
entity.Property(e => e.Nome)
.HasMaxLength(100)
.HasColumnName("nome")
.HasDefaultValueSql("('')");
entity.Property(e => e.Payload)
.HasMaxLength(500)
.HasColumnName("payload")
.HasDefaultValueSql("('')");
});
modelBuilder.Entity<Dipendenti>(entity =>
{
entity.HasKey(e => e.IdxDipendente);
entity.ToTable("Dipendenti");
entity.Property(e => e.IdxDipendente).HasColumnName("idxDipendente");
entity.Property(e => e.Attivo)
.HasColumnName("attivo")
.HasDefaultValueSql("((1))");
entity.Property(e => e.AuthKey)
.HasMaxLength(50)
.HasColumnName("authKey")
.HasDefaultValueSql("('##########')");
entity.Property(e => e.Cf)
.HasMaxLength(16)
.HasColumnName("CF")
.HasDefaultValueSql("('0000000000000000')");
entity.Property(e => e.CodDipendenteExt)
.HasMaxLength(50)
.HasColumnName("codDipendenteExt")
.HasDefaultValueSql("('')")
.HasComment("nome/codice dipendente per sistema esterno da importare");
entity.Property(e => e.CodHw)
.HasMaxLength(50)
.HasColumnName("codHw")
.HasDefaultValueSql("('')");
entity.Property(e => e.CodOrario)
.HasMaxLength(50)
.HasColumnName("codOrario");
entity.Property(e => e.Cognome).HasMaxLength(50);
entity.Property(e => e.DataAssunzione)
.HasColumnType("date")
.HasColumnName("dataAssunzione")
.HasDefaultValueSql("('1900-01-01')");
entity.Property(e => e.DataCessazione)
.HasColumnType("date")
.HasColumnName("dataCessazione")
.HasDefaultValueSql("('9999-12-31')");
entity.Property(e => e.DataNascita)
.HasColumnType("datetime")
.HasColumnName("dataNascita");
entity.Property(e => e.Dominio)
.HasMaxLength(50)
.HasColumnName("dominio")
.HasDefaultValueSql("('DOMINIO')");
entity.Property(e => e.Email)
.HasMaxLength(250)
.HasColumnName("email")
.HasDefaultValueSql("('')");
entity.Property(e => e.Gruppo)
.HasMaxLength(50)
.HasColumnName("gruppo")
.HasDefaultValueSql("('NA')");
entity.Property(e => e.LuogoNascita)
.HasMaxLength(50)
.HasColumnName("luogoNascita");
entity.Property(e => e.MailDay)
.HasColumnName("mailDay")
.HasDefaultValueSql("((0))");
entity.Property(e => e.MailLastOp)
.HasColumnName("mailLastOp")
.HasDefaultValueSql("((0))");
entity.Property(e => e.MailMonth)
.HasColumnName("mailMonth")
.HasDefaultValueSql("((0))");
entity.Property(e => e.MailWeek)
.HasColumnName("mailWeek")
.HasDefaultValueSql("((0))");
entity.Property(e => e.Matricola)
.HasMaxLength(50)
.HasColumnName("matricola");
entity.Property(e => e.NazNascita)
.HasMaxLength(50)
.HasColumnName("nazNascita");
entity.Property(e => e.Nome).HasMaxLength(50);
entity.Property(e => e.NumAuth)
.HasColumnName("numAuth")
.HasDefaultValueSql("((0))")
.HasComment("numero di impieghi della authKey");
entity.Property(e => e.ProvNascita)
.HasMaxLength(50)
.HasColumnName("provNascita");
entity.Property(e => e.Utente)
.HasMaxLength(50)
.HasColumnName("utente")
.HasDefaultValueSql("('UTENTE')");
entity.Property(e => e.WolMac)
.HasMaxLength(50)
.HasColumnName("WOL_MAC");
});
modelBuilder.Entity<RegAttivitum>(entity =>
{
entity.HasKey(e => e.IdxRa);
entity.HasIndex(e => e.Inizio, "ix_RA_inizio");
entity.HasIndex(e => new { e.IdxDipendente, e.Inizio }, "ix_idxDip");
entity.HasIndex(e => new { e.IdxFase, e.Inizio }, "ix_idxFase")
.HasFillFactor(100);
entity.HasIndex(e => new { e.Inizio, e.IdxDipendente }, "ix_inizio");
entity.Property(e => e.IdxRa).HasColumnName("idxRA");
entity.Property(e => e.Descrizione)
.HasMaxLength(500)
.HasColumnName("descrizione");
entity.Property(e => e.Fine)
.HasColumnType("datetime")
.HasColumnName("fine");
entity.Property(e => e.IdxDipendente).HasColumnName("idxDipendente");
entity.Property(e => e.IdxFase).HasColumnName("idxFase");
entity.Property(e => e.Importo)
.HasColumnType("decimal(19, 4)")
.HasColumnName("importo")
.HasDefaultValueSql("((0))");
entity.Property(e => e.Inizio)
.HasColumnType("datetime")
.HasColumnName("inizio");
entity.Property(e => e.OreTot)
.HasColumnType("decimal(19, 4)")
.HasColumnName("oreTot")
.HasComputedColumnSql("(CONVERT([decimal](19,4),CONVERT([decimal](19,4),datediff(minute,isnull([inizio],'19000101'),isnull([fine],'19000101')),(0))/(60),(0)))", false)
.HasComment("Ore Attività - prima era ([dbo].[f_hourInterval]([inizio],[fine])) poi sostituita per performance");
entity.HasOne(d => d.IdxDipendenteNavigation)
.WithMany(p => p.RegAttivita)
.HasForeignKey(d => d.IdxDipendente)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_RegAttivita_Dipendenti");
});
modelBuilder.Entity<RilievoTemp>(entity =>
{
entity.HasKey(e => new { e.IdxDipendente, e.DtRilievo });
entity.ToTable("RilievoTemp");
entity.Property(e => e.IdxDipendente).HasColumnName("idxDipendente");
entity.Property(e => e.DtRilievo)
.HasColumnType("datetime")
.HasColumnName("dtRilievo");
entity.Property(e => e.TempRil)
.HasColumnType("decimal(9, 3)")
.HasColumnName("tempRil");
entity.HasOne(d => d.IdxDipendenteNavigation)
.WithMany(p => p.RilievoTemps)
.HasForeignKey(d => d.IdxDipendente)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_RilievoTemp_Dipendenti");
});
modelBuilder.Entity<Timbrature>(entity =>
{
entity.HasKey(e => new { e.IdxDipendente, e.DataOra });
entity.ToTable("Timbrature");
entity.HasIndex(e => new { e.IdxDipendente, e.Entrata }, "ix_Timbrature_IdxDip_Entrata");
entity.Property(e => e.IdxDipendente).HasColumnName("idxDipendente");
entity.Property(e => e.DataOra)
.HasColumnType("datetime")
.HasColumnName("dataOra");
entity.Property(e => e.Approv)
.HasDefaultValueSql("((0))")
.HasComment("Approvazioen timbratura (default true...)");
entity.Property(e => e.CodTipoTimb)
.HasMaxLength(10)
.HasDefaultValueSql("(N'BC')");
entity.Property(e => e.Entrata).HasColumnName("entrata");
entity.Property(e => e.Ipv4)
.HasMaxLength(15)
.HasColumnName("IPv4")
.HasDefaultValueSql("(N'0.0.0.0')");
entity.HasOne(d => d.IdxDipendenteNavigation)
.WithMany(p => p.Timbratures)
.HasForeignKey(d => d.IdxDipendente)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_Timbrature_Dipendenti");
});
OnModelCreatingPartial(modelBuilder);
}
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
}