Fix model + migration x DB
This commit is contained in:
@@ -32,7 +32,7 @@ namespace MP.FileData.DatabaseModels
|
||||
public string MimeType { get; set; } = "";
|
||||
public bool Changed { get; set; } = false;
|
||||
public DateTime LastCheck { get; set; } = DateTime.Now.AddYears(-1);
|
||||
public byte[] Content { get; set; }
|
||||
public byte[] FileContent { get; set; }
|
||||
|
||||
[ForeignKey("CodArticolo")]
|
||||
public virtual ArticoloModel Articolo { get; set; }
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Controllers\" />
|
||||
<Folder Include="Migrations\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using MP.FileData;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
namespace MP.FileData.Migrations
|
||||
{
|
||||
[DbContext(typeof(MoonPro_ProgContext))]
|
||||
[Migration("20210903094836_InitDb")]
|
||||
partial class InitDb
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("Relational:Collation", "SQL_Latin1_General_CP1_CI_AS")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128)
|
||||
.HasAnnotation("ProductVersion", "5.0.9")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||
|
||||
modelBuilder.Entity("MP.FileData.DatabaseModels.ArticoloModel", b =>
|
||||
{
|
||||
b.Property<string>("CodArticolo")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("DescArticolo")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Disegno")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Tipo")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("CodArticolo");
|
||||
|
||||
b.ToTable("Articoli");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MP.FileData.DatabaseModels.FileModel", b =>
|
||||
{
|
||||
b.Property<int>("FileId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||
|
||||
b.Property<bool>("Active")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<bool>("Changed")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("CodArticolo")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<byte[]>("FileContent")
|
||||
.HasColumnType("varbinary(max)");
|
||||
|
||||
b.Property<string>("IdxMacchina")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<DateTime>("LastCheck")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime>("LastMod")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("MimeType")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Path")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("Rev")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Size")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("FileId");
|
||||
|
||||
b.HasIndex("CodArticolo");
|
||||
|
||||
b.HasIndex("IdxMacchina");
|
||||
|
||||
b.ToTable("Files");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MP.FileData.DatabaseModels.MacchinaModel", b =>
|
||||
{
|
||||
b.Property<string>("IdxMacchina")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("BasePath")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("CodMacchina")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Descrizione")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("ImgUrl")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Nome")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Note")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("ShowOrder")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("IdxMacchina");
|
||||
|
||||
b.ToTable("Macchine");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MP.FileData.DatabaseModels.FileModel", b =>
|
||||
{
|
||||
b.HasOne("MP.FileData.DatabaseModels.ArticoloModel", "Articolo")
|
||||
.WithMany()
|
||||
.HasForeignKey("CodArticolo");
|
||||
|
||||
b.HasOne("MP.FileData.DatabaseModels.MacchinaModel", "Macchina")
|
||||
.WithMany()
|
||||
.HasForeignKey("IdxMacchina");
|
||||
|
||||
b.Navigation("Articolo");
|
||||
|
||||
b.Navigation("Macchina");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace MP.FileData.Migrations
|
||||
{
|
||||
public partial class InitDb : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Articoli",
|
||||
columns: table => new
|
||||
{
|
||||
CodArticolo = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
DescArticolo = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
Disegno = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
Tipo = table.Column<string>(type: "nvarchar(max)", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Articoli", x => x.CodArticolo);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Macchine",
|
||||
columns: table => new
|
||||
{
|
||||
IdxMacchina = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
CodMacchina = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
Nome = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
Descrizione = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
BasePath = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
ImgUrl = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
Note = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
ShowOrder = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Macchine", x => x.IdxMacchina);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Files",
|
||||
columns: table => new
|
||||
{
|
||||
FileId = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
Active = table.Column<bool>(type: "bit", nullable: false),
|
||||
CodArticolo = table.Column<string>(type: "nvarchar(450)", nullable: true),
|
||||
IdxMacchina = table.Column<string>(type: "nvarchar(450)", nullable: true),
|
||||
Name = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
Rev = table.Column<int>(type: "int", nullable: false),
|
||||
LastMod = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
Size = table.Column<int>(type: "int", nullable: false),
|
||||
Path = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
MimeType = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
Changed = table.Column<bool>(type: "bit", nullable: false),
|
||||
LastCheck = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
FileContent = table.Column<byte[]>(type: "varbinary(max)", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Files", x => x.FileId);
|
||||
table.ForeignKey(
|
||||
name: "FK_Files_Articoli_CodArticolo",
|
||||
column: x => x.CodArticolo,
|
||||
principalTable: "Articoli",
|
||||
principalColumn: "CodArticolo",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
table.ForeignKey(
|
||||
name: "FK_Files_Macchine_IdxMacchina",
|
||||
column: x => x.IdxMacchina,
|
||||
principalTable: "Macchine",
|
||||
principalColumn: "IdxMacchina",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Files_CodArticolo",
|
||||
table: "Files",
|
||||
column: "CodArticolo");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Files_IdxMacchina",
|
||||
table: "Files",
|
||||
column: "IdxMacchina");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Files");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Articoli");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Macchine");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using MP.FileData;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
namespace MP.FileData.Migrations
|
||||
{
|
||||
[DbContext(typeof(MoonPro_ProgContext))]
|
||||
partial class MoonPro_ProgContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("Relational:Collation", "SQL_Latin1_General_CP1_CI_AS")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128)
|
||||
.HasAnnotation("ProductVersion", "5.0.9")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||
|
||||
modelBuilder.Entity("MP.FileData.DatabaseModels.ArticoloModel", b =>
|
||||
{
|
||||
b.Property<string>("CodArticolo")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("DescArticolo")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Disegno")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Tipo")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("CodArticolo");
|
||||
|
||||
b.ToTable("Articoli");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MP.FileData.DatabaseModels.FileModel", b =>
|
||||
{
|
||||
b.Property<int>("FileId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||
|
||||
b.Property<bool>("Active")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<bool>("Changed")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("CodArticolo")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<byte[]>("FileContent")
|
||||
.HasColumnType("varbinary(max)");
|
||||
|
||||
b.Property<string>("IdxMacchina")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<DateTime>("LastCheck")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime>("LastMod")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("MimeType")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Path")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("Rev")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Size")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("FileId");
|
||||
|
||||
b.HasIndex("CodArticolo");
|
||||
|
||||
b.HasIndex("IdxMacchina");
|
||||
|
||||
b.ToTable("Files");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MP.FileData.DatabaseModels.MacchinaModel", b =>
|
||||
{
|
||||
b.Property<string>("IdxMacchina")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("BasePath")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("CodMacchina")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Descrizione")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("ImgUrl")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Nome")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Note")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("ShowOrder")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("IdxMacchina");
|
||||
|
||||
b.ToTable("Macchine");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MP.FileData.DatabaseModels.FileModel", b =>
|
||||
{
|
||||
b.HasOne("MP.FileData.DatabaseModels.ArticoloModel", "Articolo")
|
||||
.WithMany()
|
||||
.HasForeignKey("CodArticolo");
|
||||
|
||||
b.HasOne("MP.FileData.DatabaseModels.MacchinaModel", "Macchina")
|
||||
.WithMany()
|
||||
.HasForeignKey("IdxMacchina");
|
||||
|
||||
b.Navigation("Articolo");
|
||||
|
||||
b.Navigation("Macchina");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,19 +18,42 @@ namespace MP.FileData
|
||||
|
||||
private IConfiguration _configuration;
|
||||
|
||||
[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()
|
||||
{
|
||||
}
|
||||
|
||||
public MoonPro_ProgContext(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 MoonPro_ProgContext(DbContextOptions<MoonPro_ProgContext> options) : base(options)
|
||||
{
|
||||
try
|
||||
{
|
||||
// se non ci fosse... crea o migra!
|
||||
Database.Migrate();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error(exc, "Exception during context initialization 01");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public virtual DbSet<AnagArticoli> DbSetArticoli { get; set; }
|
||||
public virtual DbSet<Macchine> DbSetMacchine { get; set; }
|
||||
public virtual DbSet<ArticoloModel> DbSetArticoli { get; set; }
|
||||
public virtual DbSet<MacchinaModel> DbSetMacchine { get; set; }
|
||||
public virtual DbSet<FileModel> DbSetProgFile { get; set; }
|
||||
|
||||
|
||||
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
|
||||
@@ -42,9 +65,14 @@ namespace MP.FileData
|
||||
if (!optionsBuilder.IsConfigured)
|
||||
{
|
||||
string connString = _configuration.GetConnectionString("Mp.Stats");
|
||||
|
||||
optionsBuilder.UseSqlServer(connString);
|
||||
//optionsBuilder.UseSqlServer("Server=SQL2016DEV;Database=MoonPro_STATS;Trusted_Connection=True;");
|
||||
if (!string.IsNullOrEmpty(connString))
|
||||
{
|
||||
optionsBuilder.UseSqlServer(connString);
|
||||
}
|
||||
else
|
||||
{
|
||||
optionsBuilder.UseSqlServer("Server=SQL2016DEV;Database=MoonPro_PROG;Trusted_Connection=True;");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,46 +80,6 @@ namespace MP.FileData
|
||||
{
|
||||
modelBuilder.HasAnnotation("Relational:Collation", "SQL_Latin1_General_CP1_CI_AS");
|
||||
|
||||
modelBuilder.Entity<AnagArticoli>(entity =>
|
||||
{
|
||||
entity.HasNoKey();
|
||||
|
||||
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<Macchine>(entity =>
|
||||
{
|
||||
entity.HasNoKey();
|
||||
|
||||
entity.ToView("v_UI_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);
|
||||
});
|
||||
|
||||
OnModelCreatingPartial(modelBuilder);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user