📑 Migration Documentation: 20230915173417_EmployeeNotesColumn.Designer.cs

Repository Path

IrbyImaging.DbContext/Migrations/20230915173417_EmployeeNotesColumn.Designer.cs

📖 Table of Contents

  1. Overview & Purpose
  2. EF Core Migrations in a Nutshell
  3. BuildTargetModel Method
  4. The EmployeeNotes Column Addition
  5. Snapshot of Core Entity Definitions
  6. Relationships & Navigation Properties
  7. Dependencies & Technologies
  8. How to Apply & Revert This Migration
  9. Sample Code & Usage Examples
  10. Conclusion

🌟 1. Overview & Purpose

This file is an auto‑generated EF Core “designer” snapshot for the migration named 20230915173417_EmployeeNotesColumn.
It represents the target model of your database schema after applying this particular migration.

  • Filename: 20230915173417_EmployeeNotesColumn.Designer.cs
  • Namespace: IrbyImaging.DbContext.Migrations
  • Migration Attribute:
    [Migration("20230915173417_EmployeeNotesColumn")]
    [DbContext(typeof(IrbyContext))]
    partial class EmployeeNotesColumn { … }
    

🎯 Key Objectives

  • Provide a snapshot of every entity, property, relationship, and mapping in the IrbyContext at this point in time.
  • Serve as a point-in-time reference for EF Core’s internal model to generate migration SQL.
  • Document the addition of the EmployeeNotes column to the Employee table (and any other changes).

🛠️ 2. EF Core Migrations in a Nutshell

Entity Framework Core migrations allow you to evolve your database schema over time:

  1. Add Migration
    dotnet ef migrations add EmployeeNotesColumn
    
  2. Review & Apply
    • Examine the generated Up() / Down() logic in *.cs.
    • Apply to the database:
      dotnet ef database update
      

This Designer file is not hand‑edited; it’s maintained by EF Core to reflect the model snapshot.


📦 3. BuildTargetModel Method

At the heart of this file is:

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

    // … hundreds of Entity configurations …
}
  • modelBuilder.HasAnnotation
    Captures EF Core product version and database conventions.

  • UseIdentityColumns
    Configures SQL Server to use IDENTITY columns by default.

  • Entity Definitions
    Within BuildTargetModel, each call to modelBuilder.Entity(...) defines:

    • CLR type & table mapping
    • Properties & column types
    • Keys, indexes, discriminators (for TPH inheritance)
    • Relationships & navigation

📝 4. The EmployeeNotes Column Addition

Before Migration

// IrbyImaging.DomainClasses.Employee (prior snapshot)
public partial class Employee {
    public Guid EmployeeId { get; set; }
    // … other properties, but NO EmployeeNotes …
}

After Migration

In the new snapshot, you’ll find:

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

    // … other properties …
    b.HasKey("EmployeeId");
    b.ToTable("Employee", "irby");
});
Aspect Before After
Column Name – EmployeeNotes
CLR Type – string
SQL Type – nvarchar(max)
Nullable – Yes (default for string columns)

Why EmployeeNotes?

  • Provide free‑form textual notes on employees.
  • Useful for HR annotations, flags, or follow‑up comments.

📊 5. Snapshot of Core Entity Definitions

This migration snapshot covers 50+ domain classes. Below is a selection highlighting key tables:

Entity Schema Key Property Notable Columns
Asset irby Id: GUID Category, Discriminator, Notes, Status
Employee irby EmployeeId: GUID FirstName, LastName, EmployeeNotes, Status
Department irby DepartmentId: GUID Name, Description, IsDeleted
Job irby JobId: GUID JdeNumber, Name
DocumentImage irby DocumentImageId Metadata + blob content + OCR fields
TimeSheetEntry irby TimeSheetEntryId DateWorked, HoursWorked, Notes
Role irby RoleId: GUID Name, Description
Permissions irby PermissionId PermissionName, PermissionDescription
CarrierType, CarrierTypeDetail irby Id / CarrierTypeDetailId Carrier, relationship details
… … … …

Tip: You can open the Migrations folder in your IDE, select the .Designer.cs file, and use “Go To Definition” to explore each entity block interactively.


🔗 6. Relationships & Navigation Properties

EF Core also captures foreign keys and navigations:

  • One‑to‑Many
    • Employee → TimeSheetEntries
    • Job → Employees
  • Many‑to‑One
    • Asset → Employee (Owner)
    • AssetModelDetail → AssetModel
  • Identity Inheritance (TPH)
    • Asset is the base for Computer, MobileDevice, Monitor, etc., using a discriminator column.

Example: Linking Employee & Department

modelBuilder.Entity("IrbyImaging.DomainClasses.Employee", b =>
{
    b.HasOne("IrbyImaging.DomainClasses.Department", "Department")
     .WithMany()
     .HasForeignKey("DepartmentId");
});

🔌 7. Dependencies & Technologies

  • .NET 7.0 / C#
  • EntityFrameworkCore 7.0.7
    • Microsoft.EntityFrameworkCore
    • Microsoft.EntityFrameworkCore.SqlServer
  • SQL Server (Relational provider)
  • Value Conversions & Identity Columns for key generation

🚀 8. How to Apply & Revert This Migration

Applying

# Update database to include EmployeeNotes column
dotnet ef database update 20230915173417_EmployeeNotesColumn

Reverting

# Roll back the last migration
dotnet ef database update [PreviousMigrationName]

Or explicitly:

dotnet ef database update 20230915171234_PriorMigration

Note: Always review *.cs (not .Designer.cs) for the Up() and Down() logic that alters the Employee table.


⚙️ 9. Sample Code & Usage Examples

Using the New Property in Code

using var context = new IrbyContext();

// Creating a new employee with notes
var employee = new Employee {
    FirstName = "Alice",
    LastName  = "Smith",
    Status    = "Active",
    EmployeeNotes = "Completed safety training on 2023-09-01."
};

context.Employees.Add(employee);
context.SaveChanges();

Querying Notes

var notes = context.Employees
                   .Where(e => e.Status=="Active")
                   .Select(e => new { e.DisplayName, e.EmployeeNotes })
                   .ToList();

foreach (var item in notes)
    Console.WriteLine($"{item.DisplayName}: {item.EmployeeNotes}");

🎯 10. Conclusion

This Designer snapshot is a vital piece of the EF Core migration infrastructure. It:

  • Captures the full model after the EmployeeNotes migration.
  • Ensures EF Core can generate accurate SQL to migrate your database schema.
  • Keeps a detailed map of entities, columns, keys, indexes, discriminators, and navigations.

🚩 Best Practices:

  • Do not hand‑edit .Designer.cs files.
  • Always review and test your generated Up() / Down() migration logic.
  • Maintain a consistent naming & versioning strategy for easy rollbacks.

Happy coding! 😊