📑 Migration Documentation: 20230915173417_EmployeeNotesColumn.Designer.cs
Repository Path
IrbyImaging.DbContext/Migrations/20230915173417_EmployeeNotesColumn.Designer.cs
📖 Table of Contents
- Overview & Purpose
- EF Core Migrations in a Nutshell
- BuildTargetModel Method
- The
EmployeeNotesColumn Addition - Snapshot of Core Entity Definitions
- Relationships & Navigation Properties
- Dependencies & Technologies
- How to Apply & Revert This Migration
- Sample Code & Usage Examples
- 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
IrbyContextat 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
EmployeeNotescolumn to theEmployeetable (and any other changes).
🛠️ 2. EF Core Migrations in a Nutshell
Entity Framework Core migrations allow you to evolve your database schema over time:
- Add Migration
dotnet ef migrations add EmployeeNotesColumn - Review & Apply
- Examine the generated
Up()/Down()logic in*.cs. - Apply to the database:
dotnet ef database update
- Examine the generated
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 useIDENTITYcolumns by default. -
Entity Definitions
WithinBuildTargetModel, each call tomodelBuilder.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.csfile, 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 → TimeSheetEntriesJob → Employees
- Many‑to‑One
Asset → Employee (Owner)AssetModelDetail → AssetModel
- Identity Inheritance (TPH)
Assetis the base forComputer,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.EntityFrameworkCoreMicrosoft.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 theUp()andDown()logic that alters theEmployeetable.
⚙️ 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
EmployeeNotesmigration. - 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.csfiles.- Always review and test your generated
Up()/Down()migration logic.- Maintain a consistent naming & versioning strategy for easy rollbacks.
Happy coding! 😊