📦 AddNewTablesForEquipmentReference2.Designer.cs Documentation

File Path:
IrbyImaging.DbContext/Migrations/20240307193255_AddNewTablesForEquipmentReference2.Designer.cs


📑 Table of Contents

  1. Overview & Purpose
  2. Migration Metadata
  3. BuildTargetModel Method
  4. New Tables Introduction
  5. Entity Relationships
  6. Dependencies & Technologies
  7. How to Use Migration
  8. Sample Code Blocks & Usage Examples
  9. UML Diagram
  10. Conclusion

1. Overview & Purpose

This auto-generated designer file represents the target database model that Entity Framework Core (EF Core) will create or verify when applying the AddNewTablesForEquipmentReference2 migration.
It contains the complete schema definition—including tables, columns, keys, indexes, discriminators, and relationships—for the IrbyContext.

Key Goals:

  • Define new tables to support equipment management (Equipment, EquipmentClass, EquipmentType).
  • Ensure identity columns, foreign keys, and mapping strategies are correctly configured.
  • Provide a point-in-time snapshot of the data model for EF Core Migrations.

2. Migration Metadata

[DbContext(typeof(IrbyContext))]
[Migration("20240307193255_AddNewTablesForEquipmentReference2")]
partial class AddNewTablesForEquipmentReference2
{
    protected override void BuildTargetModel(ModelBuilder modelBuilder) { ... }
}
  • [DbContext(typeof(IrbyContext))]
    Associates this migration with the IrbyContext class.

  • [Migration("20240307193255_AddNewTablesForEquipmentReference2")]
    Provides a timestamped identifier for ordering and applying migrations.


3. BuildTargetModel Method

The BuildTargetModel(ModelBuilder modelBuilder) method is the heart of this Designer file. It uses EF Core’s Fluent API to:

  • Annotate the database (e.g., product version, identifier length).
  • Enable SQL Server identity columns.
  • Define each entity’s properties, types, keys, indexes, and table mappings.
  • Establish relationships and navigations.

Note: This method is generated by EF Core and should not be modified manually.


4. New Tables Introduction

Below are the new tables introduced for equipment reference in this migration:

Table Name Description
Equipment Stores individual pieces of equipment.
EquipmentClass Defines classification groups for equipment.
EquipmentType Lists types of equipment linked to a class.

Equipment 🛠️

Mapped To: irby.Equipment

Column Name CLR Type SQL Type Notes
EquipmentId Guid uniqueidentifier Primary Key, value-generated.
Name string nvarchar(max) Equipment display name.
SerialNumber string nvarchar(max) Serial identifier.
PurchasePrice decimal decimal(18,2) Purchase cost.
CurrentStatus string nvarchar(max) Operational status.
DateAcquired DateTime? datetime2 Acquisition date.
JobId Guid? uniqueidentifier FK to Job.
… … … …
modelBuilder.Entity("IrbyImaging.DomainClasses.Equipment", b => {
    b.ToTable("Equipment", "irby");
    b.HasKey("EquipmentId");
    b.Property<Guid>("EquipmentId").ValueGeneratedOnAdd();
    b.Property<string>("Name").HasColumnType("nvarchar(max)");
    b.Property<string>("SerialNumber").HasColumnType("nvarchar(max)");
    b.Property<decimal>("PurchasePrice").HasColumnType("decimal(18,2)");
    b.Property<Guid?>("JobId").HasColumnType("uniqueidentifier");
    b.HasIndex("JobId");
});

EquipmentClass 🎯

Mapped To: irby.EquipmentClass

Column Name CLR Type SQL Type Notes
EquipmentClassId Guid uniqueidentifier Primary Key, auto-generated.
Name string nvarchar(max) Class name.
ClassId int int Numeric classification code.
modelBuilder.Entity("IrbyImaging.DomainClasses.EquipmentClass", b => {
    b.ToTable("EquipmentClass", "irby");
    b.HasKey("EquipmentClassId");
    b.Property<Guid>("EquipmentClassId").ValueGeneratedOnAdd();
    b.Property<string>("Name").HasColumnType("nvarchar(max)");
    b.Property<int>("ClassId").HasColumnType("int");
});

EquipmentType ⚙️

Mapped To: irby.EquipmentType

Column Name CLR Type SQL Type Notes
EquipmentTypeId Guid uniqueidentifier Primary Key, generated.
Name string nvarchar(max) Type name.
TypeId int int Numeric code.
EquipmentClassId Guid? uniqueidentifier FK to EquipmentClass.
modelBuilder.Entity("IrbyImaging.DomainClasses.EquipmentType", b => {
    b.ToTable("EquipmentType", "irby");
    b.HasKey("EquipmentTypeId");
    b.Property<Guid>("EquipmentTypeId").ValueGeneratedOnAdd();
    b.Property<string>("Name").HasColumnType("nvarchar(max)");
    b.Property<int>("TypeId").HasColumnType("int");
    b.Property<Guid?>("EquipmentClassId").HasColumnType("uniqueidentifier");
    b.HasIndex("EquipmentClassId");
});

5. Entity Relationships

  • Equipment → Job
    One-to-Many: an Equipment may be assigned to zero or one Job (JobId foreign key).

  • EquipmentType → EquipmentClass
    Each EquipmentType optionally references an EquipmentClass.

  • All other domain classes
    (Asset, Employee, FieldOffice, etc.) remain unchanged in this migration but are included in the snapshot.

Navigations are configured via .HasOne(...).WithMany(...) in relational mappings.


6. Dependencies & Technologies

  • EF Core 7.0.7
  • SQL Server provider (Microsoft.EntityFrameworkCore.SqlServer)
  • .NET 7
  • Identity Columns enabled via UseIdentityColumns for SQL Server.

7. How to Use Migration

  1. Add Migration
    dotnet ef migrations add AddNewTablesForEquipmentReference2
    
  2. Update Database
    dotnet ef database update
    
  3. Verify new tables Equipment, EquipmentClass, EquipmentType in schema irby.

8. Sample Code Blocks & Usage Examples

Query All Equipment with Class & Type

using (var ctx = new IrbyContext())
{
    var list = ctx.Set<Equipment>()
                  .Include(e => e.Job)
                  .ToList();

    foreach (var eq in list)
    {
        Console.WriteLine($"Equipment: {eq.Name}, Job: {eq.Job?.Name}");
    }
}

Creating a New Equipment Entry

var newEquipment = new Equipment {
    Name           = "Excavator 3000",
    SerialNumber   = "EX3000-XYZ",
    PurchasePrice  = 150_000m,
    CurrentStatus  = "Available",
    DateAcquired   = DateTime.UtcNow,
    EquipmentTypeId= someTypeId
};

ctx.Add(newEquipment);
ctx.SaveChanges();
Console.WriteLine($"Created Equipment with ID: {newEquipment.EquipmentId}");

9. UML Diagram

classDiagram
    class EquipmentClass {
        +Guid EquipmentClassId
        +string Name
        +int ClassId
    }
    class EquipmentType {
        +Guid EquipmentTypeId
        +string Name
        +int TypeId
        +Guid? EquipmentClassId
    }
    class Equipment {
        +Guid EquipmentId
        +string Name
        +string SerialNumber
        +decimal PurchasePrice
        +string CurrentStatus
        +DateTime? DateAcquired
        +Guid? JobId
    }
    EquipmentType --> EquipmentClass : references
    Equipment --> Job : assigned to

10. Conclusion

This Designer snapshot ensures EF Core can apply or roll back the AddNewTablesForEquipmentReference2 migration, keeping your database schema in sync with the .NET domain model.
By introducing Equipment, EquipmentClass, and EquipmentType, the system gains a robust foundation for equipment inventory, classification, and type management within the IrbyImaging solution. 🚀


✨ Happy Coding!