๐Ÿ“š Documentation: 20230915180115_EmployeeNotesColumnICCSQLSRV1.Designer.cs

Auto-generated EF Core migration designer file for adding the EmployeeNotes column to the IrbyImaging database.


๐Ÿ“‘ Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Key Functional Areas
  4. Data Models (Entities) Snapshot
  5. Relationships & Navigation Properties
  6. Migration Details: EmployeeNotes Column
  7. Deep Dive: BuildTargetModel Method
  8. Usage Example: Applying the Migration
  9. UML Diagram (Mermaid)
  10. โš ๏ธ Potential Pitfalls & Notes
  11. ๐Ÿ Conclusion

1. Overview & Purpose

This file is an auto-generated designer for the EF Core migration named
20230915180115_EmployeeNotesColumnICCSQLSRV1. Its core responsibilities are:

  • Decorators:

    • [DbContext(typeof(IrbyContext))] links the migration to your IrbyContext.
    • [Migration("20230915180115_EmployeeNotesColumnICCSQLSRV1")] stamps a unique identifier.
  • BuildTargetModel(ModelBuilder modelBuilder):

    • Describes the target EF Core data model after applying this migration.
    • Used by EF Core tools to compute diffs between current and target schemas.

โญ Note: This file is not manually edited. Itโ€™s regenerated each time you scaffold a migration.


2. Dependencies & Technologies

Technology Version Purpose
.NET 7.0 7.0.x Target framework
Microsoft.EntityFrameworkCore 7.0.7 ORM for building the model
Microsoft.EntityFrameworkCore.SqlServer 7.0.7 SQL Server provider
Microsoft.EntityFrameworkCore.Design 7.0.7 Design-time tools for migrations

๐Ÿ”— References


3. Key Functional Areas

  1. Annotations & Conventions

    • .HasAnnotation("ProductVersion", "7.0.7")
    • .UseIdentityColumns() for SQL Server auto-increment strategy.
  2. Entity Definitions

    • Each domain entity (e.g., Employee, Asset, DocumentImage) is configured via modelBuilder.Entity(...).
  3. Property Configuration

    • Column types, max lengths, required flags, default value strategies.
  4. Discriminator & TPH

    • Assets employ Table-per-Hierarchy (.UseTphMappingStrategy()) featuring a Discriminator column.
  5. Indexes & Constraints

    • Unique constraints (e.g., on Employee.JdeNumber).
    • Foreign-key indexes for navigation.

4. Data Models (Entities) Snapshot

Below is a sample of the massive entity list. Each entry maps a .NET type to a relational table.

Entity (CLR Type) Table (Schema) Primary Key
IrbyImaging.DomainClasses.Employee irby.Employee EmployeeId
IrbyImaging.DomainClasses.Asset irby.Asset Id
IrbyImaging.DomainClasses.DocumentImage irby.DocumentImage DocumentImageId
IrbyImaging.DomainClasses.Ticket irby.Ticket Id
IrbyImaging.DomainClasses.TimeSheetEntry irby.TimeSheetEntry TimeSheetEntryId

๐Ÿ” Over 70+ entities (e.g., AssetModel, CarrierType, OperatingSystem, ODS* views, etc.)
Each has typed properties (Guid, string, decimal, DateTime, etc.) and relational configurations.


5. Relationships & Navigation Properties

Entities are wired together via fluent API:

  • One-to-Many
    • Employee (1) โ†โ†’ (n) Asset
    • Role (1) โ†โ†’ (n) LinkRolePermission
  • Many-to-One
    • Asset โ†’ Model
    • FieldOffice โ†’ Manager (Employee)
modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b =>
{
  b.HasOne("IrbyImaging.DomainClasses.Employee", "Owner")
   .WithMany("Assets")
   .HasForeignKey("OwnerId");
});
  • TPH Discriminator
    • All Asset subtypes (Computer, MobileDevice, OfficePrinter, etc.) stored in one table with .HasDiscriminator().

6. Migration Details: EmployeeNotes Column

This migrationโ€™s primary purpose is to add the new EmployeeNotes property/column:

  • CLR Property on Employee:
    public string EmployeeNotes { get; set; }
    
  • DB Column:
    ALTER TABLE [irby].[Employee]
    ADD [EmployeeNotes] NVARCHAR(MAX) NULL;
    

Within BuildTargetModel, youโ€™ll find:

modelBuilder.Entity("IrbyImaging.DomainClasses.Employee", b =>
{
  // ...
  b.Property<string>("EmployeeNotes")
   .HasColumnType("nvarchar(max)");
  // ...
});

7. Deep Dive: BuildTargetModel Method

This method configures every entity in one pass:

protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
  #pragma warning disable 612, 618
  modelBuilder
    .HasAnnotation("ProductVersion", "7.0.7")
    .HasAnnotation("Relational:MaxIdentifierLength", 128);

  SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

  // --- Entity: Employee ---
  modelBuilder.Entity("IrbyImaging.DomainClasses.Employee", b =>
  {
    b.Property<Guid>("EmployeeId")
     .ValueGeneratedOnAdd()
     .HasColumnType("uniqueidentifier");

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

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

    b.Property<string>("EmployeeNotes")            // โ† NEW
     .HasColumnType("nvarchar(max)");

    b.HasKey("EmployeeId");
    b.HasIndex("JdeNumber").IsUnique().HasFilter("[JdeNumber] IS NOT NULL");
    b.ToTable("Employee", "irby");
  });
  // ... (70+ other entities)
  #pragma warning restore 612, 618
}
  • Annotations suppress warnings on obsolete APIs.
  • Entities are fully wired here; EF uses this to generate SQL scripts for Up()/Down().

8. Usage Example: Applying the Migration

# 1. Add migration (if not yet created)
dotnet ef migrations add EmployeeNotesColumnICCSQLSRV1 \
  --context IrbyContext \
  --output-dir IrbyImaging.DbContext/Migrations

# 2. Apply migration to database
dotnet ef database update --context IrbyContext

Once applied, you may:

  • Query/update Employee.EmployeeNotes via your DbContext.
  • Scaffold new migrations for further schema changes.

9. UML Diagram (Mermaid)

classDiagram
  class Employee {
    +Guid EmployeeId
    +string FirstName
    +string LastName
    +string EmployeeNotes
    +string Status
  }
  class Department {
    +Guid DepartmentId
    +string Name
  }
  class Asset {
    +Guid Id
    +string Discriminator
    +string Notes
    +DateTimeOffset PurchaseDate
  }
  Employee --> Department : DepartmentId
  Employee --> Asset : * owns *

๐Ÿ“ This simplified diagram highlights the Employeeโ†”Department and Employeeโ†”Asset relationships.


โš ๏ธ Potential Pitfalls & Notes

  • Regeneration: The designer file is re-generatedโ€”do not manually edit it.
  • Naming Conventions: Ensure your CLR property matches your intended DB column.
  • Schema Sync: Always verify the irby schema exists in your SQL Server instance.
  • Backups: Run DB backups before large migrations.
  • Multiple Contexts: If you have more DbContext classes, explicitly specify --context.

๐Ÿ Conclusion

The 20230915180115_EmployeeNotesColumnICCSQLSRV1.Designer.cs file is a snapshot of your EF Core model after adding the EmployeeNotes column. It enables EFโ€™s design-time tools to understand:

  • What changed in your model.
  • How to scaffold SQL for Up() / Down().
  • Which relationships, indexes, and configurations exist.

Embrace migrations as a first-class citizen in your DevOps pipelineโ€”this file is one cog in that machinery. Happy coding! ๐ŸŽ‰


Generated by EF Core 7.0 tooling