chore: Update DbContext for new entity relationships
Updates ApplicationDbContext to configure MaterialStockLength and revised ProjectPart relationships. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -11,12 +11,12 @@ public class ApplicationDbContext : DbContext
|
|||||||
}
|
}
|
||||||
|
|
||||||
public DbSet<Material> Materials => Set<Material>();
|
public DbSet<Material> Materials => Set<Material>();
|
||||||
|
public DbSet<MaterialStockLength> MaterialStockLengths => Set<MaterialStockLength>();
|
||||||
public DbSet<Supplier> Suppliers => Set<Supplier>();
|
public DbSet<Supplier> Suppliers => Set<Supplier>();
|
||||||
public DbSet<SupplierStock> SupplierStocks => Set<SupplierStock>();
|
public DbSet<SupplierStock> SupplierStocks => Set<SupplierStock>();
|
||||||
public DbSet<CuttingTool> CuttingTools => Set<CuttingTool>();
|
public DbSet<CuttingTool> CuttingTools => Set<CuttingTool>();
|
||||||
public DbSet<Project> Projects => Set<Project>();
|
public DbSet<Project> Projects => Set<Project>();
|
||||||
public DbSet<ProjectPart> ProjectParts => Set<ProjectPart>();
|
public DbSet<ProjectPart> ProjectParts => Set<ProjectPart>();
|
||||||
public DbSet<ProjectStockBin> ProjectStockBins => Set<ProjectStockBin>();
|
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
@@ -32,6 +32,21 @@ public class ApplicationDbContext : DbContext
|
|||||||
entity.Property(e => e.CreatedAt).HasDefaultValueSql("GETUTCDATE()");
|
entity.Property(e => e.CreatedAt).HasDefaultValueSql("GETUTCDATE()");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// MaterialStockLength
|
||||||
|
modelBuilder.Entity<MaterialStockLength>(entity =>
|
||||||
|
{
|
||||||
|
entity.HasKey(e => e.Id);
|
||||||
|
entity.Property(e => e.LengthInches).HasPrecision(10, 4);
|
||||||
|
entity.Property(e => e.Notes).HasMaxLength(255);
|
||||||
|
|
||||||
|
entity.HasOne(e => e.Material)
|
||||||
|
.WithMany(m => m.StockLengths)
|
||||||
|
.HasForeignKey(e => e.MaterialId)
|
||||||
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
|
|
||||||
|
entity.HasIndex(e => new { e.MaterialId, e.LengthInches }).IsUnique();
|
||||||
|
});
|
||||||
|
|
||||||
// Supplier
|
// Supplier
|
||||||
modelBuilder.Entity<Supplier>(entity =>
|
modelBuilder.Entity<Supplier>(entity =>
|
||||||
{
|
{
|
||||||
@@ -75,13 +90,9 @@ public class ApplicationDbContext : DbContext
|
|||||||
{
|
{
|
||||||
entity.HasKey(e => e.Id);
|
entity.HasKey(e => e.Id);
|
||||||
entity.Property(e => e.Name).HasMaxLength(100).IsRequired();
|
entity.Property(e => e.Name).HasMaxLength(100).IsRequired();
|
||||||
|
entity.Property(e => e.Customer).HasMaxLength(100);
|
||||||
entity.Property(e => e.CreatedAt).HasDefaultValueSql("GETUTCDATE()");
|
entity.Property(e => e.CreatedAt).HasDefaultValueSql("GETUTCDATE()");
|
||||||
|
|
||||||
entity.HasOne(e => e.Material)
|
|
||||||
.WithMany(m => m.Projects)
|
|
||||||
.HasForeignKey(e => e.MaterialId)
|
|
||||||
.OnDelete(DeleteBehavior.SetNull);
|
|
||||||
|
|
||||||
entity.HasOne(e => e.CuttingTool)
|
entity.HasOne(e => e.CuttingTool)
|
||||||
.WithMany(t => t.Projects)
|
.WithMany(t => t.Projects)
|
||||||
.HasForeignKey(e => e.CuttingToolId)
|
.HasForeignKey(e => e.CuttingToolId)
|
||||||
@@ -92,25 +103,18 @@ public class ApplicationDbContext : DbContext
|
|||||||
modelBuilder.Entity<ProjectPart>(entity =>
|
modelBuilder.Entity<ProjectPart>(entity =>
|
||||||
{
|
{
|
||||||
entity.HasKey(e => e.Id);
|
entity.HasKey(e => e.Id);
|
||||||
entity.Property(e => e.Name).HasMaxLength(100).IsRequired();
|
entity.Property(e => e.Name).HasMaxLength(100);
|
||||||
entity.Property(e => e.LengthInches).HasPrecision(10, 4);
|
entity.Property(e => e.LengthInches).HasPrecision(10, 4);
|
||||||
|
|
||||||
entity.HasOne(e => e.Project)
|
entity.HasOne(e => e.Project)
|
||||||
.WithMany(p => p.Parts)
|
.WithMany(p => p.Parts)
|
||||||
.HasForeignKey(e => e.ProjectId)
|
.HasForeignKey(e => e.ProjectId)
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
});
|
|
||||||
|
|
||||||
// ProjectStockBin
|
entity.HasOne(e => e.Material)
|
||||||
modelBuilder.Entity<ProjectStockBin>(entity =>
|
.WithMany(m => m.ProjectParts)
|
||||||
{
|
.HasForeignKey(e => e.MaterialId)
|
||||||
entity.HasKey(e => e.Id);
|
.OnDelete(DeleteBehavior.Restrict);
|
||||||
entity.Property(e => e.LengthInches).HasPrecision(10, 4);
|
|
||||||
|
|
||||||
entity.HasOne(e => e.Project)
|
|
||||||
.WithMany(p => p.StockBins)
|
|
||||||
.HasForeignKey(e => e.ProjectId)
|
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Seed default cutting tools
|
// Seed default cutting tools
|
||||||
|
|||||||
@@ -122,6 +122,39 @@ namespace CutList.Web.Migrations
|
|||||||
b.ToTable("Materials");
|
b.ToTable("Materials");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("CutList.Web.Data.Entities.MaterialStockLength", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<bool>("IsActive")
|
||||||
|
.HasColumnType("bit");
|
||||||
|
|
||||||
|
b.Property<decimal>("LengthInches")
|
||||||
|
.HasPrecision(10, 4)
|
||||||
|
.HasColumnType("decimal(10,4)");
|
||||||
|
|
||||||
|
b.Property<int>("MaterialId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<string>("Notes")
|
||||||
|
.HasMaxLength(255)
|
||||||
|
.HasColumnType("nvarchar(255)");
|
||||||
|
|
||||||
|
b.Property<int>("Quantity")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("MaterialId", "LengthInches")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("MaterialStockLengths");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("CutList.Web.Data.Entities.Project", b =>
|
modelBuilder.Entity("CutList.Web.Data.Entities.Project", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@@ -135,10 +168,11 @@ namespace CutList.Web.Migrations
|
|||||||
.HasColumnType("datetime2")
|
.HasColumnType("datetime2")
|
||||||
.HasDefaultValueSql("GETUTCDATE()");
|
.HasDefaultValueSql("GETUTCDATE()");
|
||||||
|
|
||||||
b.Property<int?>("CuttingToolId")
|
b.Property<string>("Customer")
|
||||||
.HasColumnType("int");
|
.HasMaxLength(100)
|
||||||
|
.HasColumnType("nvarchar(100)");
|
||||||
|
|
||||||
b.Property<int?>("MaterialId")
|
b.Property<int?>("CuttingToolId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<string>("Name")
|
b.Property<string>("Name")
|
||||||
@@ -156,8 +190,6 @@ namespace CutList.Web.Migrations
|
|||||||
|
|
||||||
b.HasIndex("CuttingToolId");
|
b.HasIndex("CuttingToolId");
|
||||||
|
|
||||||
b.HasIndex("MaterialId");
|
|
||||||
|
|
||||||
b.ToTable("Projects");
|
b.ToTable("Projects");
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -173,6 +205,9 @@ namespace CutList.Web.Migrations
|
|||||||
.HasPrecision(10, 4)
|
.HasPrecision(10, 4)
|
||||||
.HasColumnType("decimal(10,4)");
|
.HasColumnType("decimal(10,4)");
|
||||||
|
|
||||||
|
b.Property<int>("MaterialId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<string>("Name")
|
b.Property<string>("Name")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasMaxLength(100)
|
.HasMaxLength(100)
|
||||||
@@ -189,42 +224,13 @@ namespace CutList.Web.Migrations
|
|||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("MaterialId");
|
||||||
|
|
||||||
b.HasIndex("ProjectId");
|
b.HasIndex("ProjectId");
|
||||||
|
|
||||||
b.ToTable("ProjectParts");
|
b.ToTable("ProjectParts");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("CutList.Web.Data.Entities.ProjectStockBin", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
|
||||||
|
|
||||||
b.Property<decimal>("LengthInches")
|
|
||||||
.HasPrecision(10, 4)
|
|
||||||
.HasColumnType("decimal(10,4)");
|
|
||||||
|
|
||||||
b.Property<int>("Priority")
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<int>("ProjectId")
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<int>("Quantity")
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<int>("SortOrder")
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.HasIndex("ProjectId");
|
|
||||||
|
|
||||||
b.ToTable("ProjectStockBins");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("CutList.Web.Data.Entities.Supplier", b =>
|
modelBuilder.Entity("CutList.Web.Data.Entities.Supplier", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@@ -297,6 +303,17 @@ namespace CutList.Web.Migrations
|
|||||||
b.ToTable("SupplierStocks");
|
b.ToTable("SupplierStocks");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("CutList.Web.Data.Entities.MaterialStockLength", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("CutList.Web.Data.Entities.Material", "Material")
|
||||||
|
.WithMany("StockLengths")
|
||||||
|
.HasForeignKey("MaterialId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Material");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("CutList.Web.Data.Entities.Project", b =>
|
modelBuilder.Entity("CutList.Web.Data.Entities.Project", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("CutList.Web.Data.Entities.CuttingTool", "CuttingTool")
|
b.HasOne("CutList.Web.Data.Entities.CuttingTool", "CuttingTool")
|
||||||
@@ -304,34 +321,24 @@ namespace CutList.Web.Migrations
|
|||||||
.HasForeignKey("CuttingToolId")
|
.HasForeignKey("CuttingToolId")
|
||||||
.OnDelete(DeleteBehavior.SetNull);
|
.OnDelete(DeleteBehavior.SetNull);
|
||||||
|
|
||||||
b.HasOne("CutList.Web.Data.Entities.Material", "Material")
|
|
||||||
.WithMany("Projects")
|
|
||||||
.HasForeignKey("MaterialId")
|
|
||||||
.OnDelete(DeleteBehavior.SetNull);
|
|
||||||
|
|
||||||
b.Navigation("CuttingTool");
|
b.Navigation("CuttingTool");
|
||||||
|
|
||||||
b.Navigation("Material");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("CutList.Web.Data.Entities.ProjectPart", b =>
|
modelBuilder.Entity("CutList.Web.Data.Entities.ProjectPart", b =>
|
||||||
{
|
{
|
||||||
|
b.HasOne("CutList.Web.Data.Entities.Material", "Material")
|
||||||
|
.WithMany("ProjectParts")
|
||||||
|
.HasForeignKey("MaterialId")
|
||||||
|
.OnDelete(DeleteBehavior.Restrict)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
b.HasOne("CutList.Web.Data.Entities.Project", "Project")
|
b.HasOne("CutList.Web.Data.Entities.Project", "Project")
|
||||||
.WithMany("Parts")
|
.WithMany("Parts")
|
||||||
.HasForeignKey("ProjectId")
|
.HasForeignKey("ProjectId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
b.Navigation("Project");
|
b.Navigation("Material");
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("CutList.Web.Data.Entities.ProjectStockBin", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("CutList.Web.Data.Entities.Project", "Project")
|
|
||||||
.WithMany("StockBins")
|
|
||||||
.HasForeignKey("ProjectId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("Project");
|
b.Navigation("Project");
|
||||||
});
|
});
|
||||||
@@ -362,7 +369,9 @@ namespace CutList.Web.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("CutList.Web.Data.Entities.Material", b =>
|
modelBuilder.Entity("CutList.Web.Data.Entities.Material", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("Projects");
|
b.Navigation("ProjectParts");
|
||||||
|
|
||||||
|
b.Navigation("StockLengths");
|
||||||
|
|
||||||
b.Navigation("SupplierStocks");
|
b.Navigation("SupplierStocks");
|
||||||
});
|
});
|
||||||
@@ -370,8 +379,6 @@ namespace CutList.Web.Migrations
|
|||||||
modelBuilder.Entity("CutList.Web.Data.Entities.Project", b =>
|
modelBuilder.Entity("CutList.Web.Data.Entities.Project", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("Parts");
|
b.Navigation("Parts");
|
||||||
|
|
||||||
b.Navigation("StockBins");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("CutList.Web.Data.Entities.Supplier", b =>
|
modelBuilder.Entity("CutList.Web.Data.Entities.Supplier", b =>
|
||||||
|
|||||||
Reference in New Issue
Block a user