šŸ“š Documentation for 20240801143541_AddWorkOrderType.Designer.cs

Auto‑Generated EF Core Migration Designer
Namespace: IrbyImaging.DbContext.Migrations
Context: IrbyContext
Migration: 20240801143541_AddWorkOrderType


šŸš€ Table of Contents

  1. Overview & Purpose
  2. Migration Metadata
  3. BuildTargetModel Method
  4. Change Summary: Add WorkOrderType
  5. Running & Applying the Migration
  6. Working with the New Property in Code
  7. UML Class Diagram
  8. Dependencies & Technologies
  9. Conclusion

1. Overview & Purpose

This file is an EF Core Designer snapshot generated by the [dotnet ef migrations add] operation. It contains the target model (i.e., the full database schema in code) after the AddWorkOrderType migration has been applied.

  • It should not be hand‑edited.
  • EF Core uses it at design‑time to compare model differences and scaffold future migrations.

The key purpose of AddWorkOrderType.Designer.cs is to record:

  • All entities & their properties
  • Keys, indexes, discriminators (for TPH inheritance)
  • Relationships and navigation properties
  • The newly introduced WorkOrderType column on the WorkOrder table

2. Migration Metadata

Attribute Value
DbContext IrbyContext
Migration Id 20240801143541_AddWorkOrderType
Product Version (EF Core) 7.0.7
MaxIdentifierLength 128
Provider Microsoft.EntityFrameworkCore.SqlServer (implied)
Identity Strategy UseIdentityColumns
[DbContext(typeof(IrbyContext))]
[Migration("20240801143541_AddWorkOrderType")]
partial class AddWorkOrderType
{
    protected override void BuildTargetModel(ModelBuilder modelBuilder)
    {
        modelBuilder
            .HasAnnotation("ProductVersion", "7.0.7")
            .HasAnnotation("Relational:MaxIdentifierLength", 128);
        SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
        // … entity configurations follow …
    }
}

3. BuildTargetModel Method

The BuildTargetModel method reconstructs the complete EF Core model as a series of fluent‑API calls on ModelBuilder.

3.1 Model Annotations

  • ProductVersion: Tracks the EF Core version used to generate the model.
  • Relational:MaxIdentifierLength: Ensures compatibility with SQL Server’s 128‑character limit.
modelBuilder
    .HasAnnotation("ProductVersion", "7.0.7")
    .HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

3.2 Entity Configurations

šŸ“‹ Example: WorkOrder Entity
(Only the relevant properties are shown; the full file defines 60+ entities.)

modelBuilder.Entity("IrbyImaging.DomainClasses.WorkOrder", b =>
{
    b.Property<Guid>("WorkOrderId")
        .ValueGeneratedOnAdd()
        .HasColumnType("uniqueidentifier");

    b.Property<string>("WorkOrderNumber")
        .HasColumnType("nvarchar(max)");

    b.Property<string>("Status")
        .HasColumnType("nvarchar(max)");

    // NEW in this migration
    b.Property<string>("WorkOrderType")
        .HasColumnType("nvarchar(max)");

    b.HasKey("WorkOrderId");
    b.HasIndex("JobId");
    b.HasIndex("ProjectManagerId");
    b.ToTable("WorkOrder", "irby");
});

Other entities include Asset, Employee, Job, DocumentImage, TempDocumentData, etc. Each is defined with:

  • Properties (b.Property<T>(…))
  • Keys (b.HasKey(…))
  • Indexes (b.HasIndex(…))
  • Table Mappings (b.ToTable(…))
  • Discriminators for TPH inheritance (b.HasDiscriminator(…))

3.3 Relationships & Navigations

Relationships between entities are configured at the bottom of the BuildTargetModel method. Example:

modelBuilder.Entity("IrbyImaging.DomainClasses.WorkOrder", b =>
{
    b.HasOne("IrbyImaging.DomainClasses.Job", "Job")
     .WithMany()
     .HasForeignKey("JobId")
     .OnDelete(DeleteBehavior.Cascade)
     .IsRequired();

    b.HasOne("IrbyImaging.DomainClasses.Employee", "Employee")
     .WithMany()
     .HasForeignKey("ProjectManagerId");

    b.Navigation("Employee");
    b.Navigation("Job");
});

4. Change Summary: Add WorkOrderType

This migration’s sole purpose is to introduce a new string column named WorkOrderType to the WorkOrder table:

Table Column CLR Type SQL Type Allows Nulls
WorkOrder WorkOrderType string nvarchar(max) Yes

Impact

  • All existing WorkOrder records will have NULL in WorkOrderType until updated.
  • Developers can categorize work orders by type (e.g., ā€œInspectionā€, ā€œRepairā€, ā€œMaintenanceā€).

5. Running & Applying the Migration

5.1 Add & Update Database

  1. Add Migration (already done):
    dotnet ef migrations add AddWorkOrderType
    
  2. Apply to Database:
    dotnet ef database update
    

    This will apply 20240801143541_AddWorkOrderType, adding the new column.

5.2 CLI / PMC Examples

  • Package Manager Console
    Add-Migration AddWorkOrderType
    Update-Database
    
  • .NET CLI
    dotnet ef migrations add AddWorkOrderType
    dotnet ef database update
    

6. Working with the New Property in Code

6.1 Domain Class Snippet

Ensure the domain entity WorkOrder in IrbyImaging.DomainClasses is updated:

public class WorkOrder
{
    public Guid WorkOrderId { get; set; }
    public string WorkOrderNumber { get; set; }
    public string Status { get; set; }

    // Newly added:
    public string? WorkOrderType { get; set; }

    // Navigation:
    public Job Job { get; set; }
    public Employee? ProjectManager { get; set; }
}

6.2 CRUD Example

// 1. Creating a new WorkOrder with a type
var workOrder = new WorkOrder {
    WorkOrderNumber = "WO-12345",
    Status           = "Open",
    WorkOrderType    = "Inspection",
    JobId            = existingJobId
};
context.WorkOrders.Add(workOrder);
await context.SaveChangesAsync();

// 2. Query by WorkOrderType
var inspections = await context.WorkOrders
    .Where(wo => wo.WorkOrderType == "Inspection")
    .ToListAsync();

7. UML Class Diagram

classDiagram
    class WorkOrder {
        +Guid WorkOrderId
        +string WorkOrderNumber
        +string Status
        +string? WorkOrderType
        +DateTime? DateAssigned
        +DateTime? DateStart
        +DateTime? DateComplete
    }
    WorkOrder --> Job : JobId
    WorkOrder --> Employee : ProjectManagerId

āš™ļø Mermaid diagram showing the WorkOrder entity, its key properties, and relationships.


8. Dependencies & Technologies

  • .NET 7 (C#)
  • Entity Framework Core 7.0.7
  • Microsoft.EntityFrameworkCore.SqlServer
  • EF Core Migrations (Designer Annotations)
  • SQL Server (Relational Database)

9. Conclusion

This Designer file is a snapshot of your EF Core model after applying the AddWorkOrderType migration. It records:

  • All entities, properties, indexes, keys, and relationships
  • The new WorkOrderType column on the WorkOrder table

Keep your domain classes and migration files in sync. After applying the migration:

  1. Update your WorkOrder domain class with the new property.
  2. Use LINQ to CRUD or filter by WorkOrderType.
  3. Rerun dotnet ef migrations add for future schema changes—EF will diff against this snapshot.

Happy coding! šŸŽ‰