Fix init DB

This commit is contained in:
Samuele Locatelli
2021-09-03 14:58:55 +02:00
parent e54a77d85d
commit 17ca3eee8e
6 changed files with 109 additions and 3 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ namespace MP.FileData.DatabaseModels
public string BasePath { get; set; } = "";
public string ImgUrl { get; set; } = "";
public string Note { get; set; } = "";
public int ShowOrder { get; set; } = 0;
public int ShowOrder { get; set; } = 999;
#endregion Public Properties
}
@@ -10,7 +10,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace MP.FileData.Migrations
{
[DbContext(typeof(MoonPro_ProgContext))]
[Migration("20210903094836_InitDb")]
[Migration("20210903125648_InitDb")]
partial class InitDb
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@@ -39,6 +39,15 @@ namespace MP.FileData.Migrations
b.HasKey("CodArticolo");
b.ToTable("Articoli");
b.HasData(
new
{
CodArticolo = "ND",
DescArticolo = "--- Tutti ---",
Disegno = "",
Tipo = "ND"
});
});
modelBuilder.Entity("MP.FileData.DatabaseModels.FileModel", b =>
@@ -122,6 +131,19 @@ namespace MP.FileData.Migrations
b.HasKey("IdxMacchina");
b.ToTable("Macchine");
b.HasData(
new
{
IdxMacchina = "0",
BasePath = "",
CodMacchina = "0",
Descrizione = "--- Tutte ---",
ImgUrl = "",
Nome = "--- Tutte ---",
Note = "",
ShowOrder = 0
});
});
modelBuilder.Entity("MP.FileData.DatabaseModels.FileModel", b =>
@@ -75,6 +75,16 @@ namespace MP.FileData.Migrations
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.InsertData(
table: "Articoli",
columns: new[] { "CodArticolo", "DescArticolo", "Disegno", "Tipo" },
values: new object[] { "ND", "--- Tutti ---", "", "ND" });
migrationBuilder.InsertData(
table: "Macchine",
columns: new[] { "IdxMacchina", "BasePath", "CodMacchina", "Descrizione", "ImgUrl", "Nome", "Note", "ShowOrder" },
values: new object[] { "0", "", "0", "--- Tutte ---", "", "--- Tutte ---", "", 0 });
migrationBuilder.CreateIndex(
name: "IX_Files_CodArticolo",
table: "Files",
@@ -37,6 +37,15 @@ namespace MP.FileData.Migrations
b.HasKey("CodArticolo");
b.ToTable("Articoli");
b.HasData(
new
{
CodArticolo = "ND",
DescArticolo = "--- Tutti ---",
Disegno = "",
Tipo = "ND"
});
});
modelBuilder.Entity("MP.FileData.DatabaseModels.FileModel", b =>
@@ -120,6 +129,19 @@ namespace MP.FileData.Migrations
b.HasKey("IdxMacchina");
b.ToTable("Macchine");
b.HasData(
new
{
IdxMacchina = "0",
BasePath = "",
CodMacchina = "0",
Descrizione = "--- Tutte ---",
ImgUrl = "",
Nome = "--- Tutte ---",
Note = "",
ShowOrder = 0
});
});
modelBuilder.Entity("MP.FileData.DatabaseModels.FileModel", b =>
+34
View File
@@ -0,0 +1,34 @@
using Microsoft.EntityFrameworkCore;
using MP.FileData.DatabaseModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MP.FileData
{
public static class ModelBuilderExtensions
{
#region Public Methods
/// <summary>
/// Estensione per seed iniziale dei dati nel DB
/// </summary>
/// <param name="modelBuilder"></param>
public static void Seed(this ModelBuilder modelBuilder)
{
// inizializzazione dei valori di default x USER
modelBuilder.Entity<MacchinaModel>().HasData(
new MacchinaModel { IdxMacchina = "0", CodMacchina = "0", Descrizione = "--- Tutte ---", Nome = "--- Tutte ---", BasePath = "", ImgUrl = "", Note = "", ShowOrder = 0 }
);
// inizializzazione dei valori di default x Plant
modelBuilder.Entity<ArticoloModel>().HasData(
new ArticoloModel { CodArticolo = "ND", DescArticolo = "--- Tutti ---", Disegno = "", Tipo = "ND" }
);
}
#endregion Public Methods
}
}
+19 -1
View File
@@ -13,11 +13,16 @@ namespace MP.FileData
{
public partial class MoonPro_ProgContext : 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 MoonPro_ProgContext()
{
@@ -50,15 +55,23 @@ namespace MP.FileData
}
}
#endregion Public Constructors
#region Public Properties
public virtual DbSet<ArticoloModel> DbSetArticoli { get; set; }
public virtual DbSet<MacchinaModel> DbSetMacchine { get; set; }
public virtual DbSet<FileModel> DbSetProgFile { 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)
{
@@ -80,7 +93,12 @@ namespace MP.FileData
{
modelBuilder.HasAnnotation("Relational:Collation", "SQL_Latin1_General_CP1_CI_AS");
//
modelBuilder.Seed();
OnModelCreatingPartial(modelBuilder);
}
#endregion Protected Methods
}
}
}