📝 Documentation: AddSSNColumn.Designer.cs
File: IrbyImaging.DbContext/Migrations/20240124141838_AddSSNColumn.Designer.cs
Author: Entity Framework Core (auto-generated)
Generated on: January 24, 2024 at 14:18:38 (UTC)
Context: This file is part of the EF Core Migrations history for the IrbyImaging application. It represents the model snapshot after applying the AddSSNColumn migration.
📑 Table of Contents
- Overview & Purpose
- File Structure
- Dependencies & Technologies
- Key Functional Areas
- Data Models & Entity Configurations
- Model Relationships
- Helper Methods & Utilities
- How EF Core Migrations Work
- Sample Code & Usage
- Mermaid UML Diagram
- Conclusion
🎯 1. Overview & Purpose
The AddSSNColumn.Designer.cs file is an auto-generated model snapshot created by Entity Framework Core (EF Core) as part of the AddSSNColumn migration. It defines the complete database schema (entities, properties, relationships, indexes) after the migration has been applied.
-
Why it exists:
- To allow EF Core to compare the current model with previous snapshots when adding, updating, or rolling back migrations.
- To keep a versioned “picture” of all entities so that subsequent migrations only include incremental changes.
-
What changed in
AddSSNColumn:- A new property
LastFourSSN(string) was added to theEmployeeentity — storing the last four digits of an employee’s SSN for privacy-compliant lookup.
- A new property
📂 2. File Structure
IrbyImaging.DbContext
└── Migrations
└── 20240124141838_AddSSNColumn
└── AddSSNColumn.Designer.cs ← Auto‐generated snapshot
- Namespace:
IrbyImaging.DbContext.Migrations - Class:
partial class AddSSNColumn - Key Method:
protected override void BuildTargetModel(ModelBuilder modelBuilder) { … }
🔧 3. Dependencies & Technologies
| Technology / Package | Purpose |
|---|---|
| Microsoft.EntityFrameworkCore (7.0.7) | ORM for .NET, model building & change tracking |
| Microsoft.EntityFrameworkCore.SqlServer | SQL Server provider (identity columns, data types) |
| Microsoft.EntityFrameworkCore.Migrations | Migration scaffolding & metadata |
| C# (.NET 7) | Language & runtime |
- Nullable Annotations:
#nullable disable— simplifies auto‑generation by disabling nullable context. - Warning Suppression:
#pragma warning disable 612, 618— ignores obsolete‐API warnings in generated code.
⚙️ 4. Key Functional Areas
-
Annotations & Conventions
.HasAnnotation("ProductVersion", "7.0.7")SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder)
-
Entity Definitions
- Each
modelBuilder.Entity("...DomainClasses.Xxx", b => { ... })block describes one table.
- Each
-
Property Mappings
.Property<type>("Name")→ CLR type, column name, SQL type, nullability, default values.
-
Keys & Indexes
.HasKey("Id"),.HasIndex("ForeignKey"),.IsUnique(),.HasFilter(...)
-
Relationships / Navigations
.HasOne(...).WithMany(...).HasForeignKey(...).OnDelete(...)
🗃️ 5. Data Models & Entity Configurations
Below is a sample of some key entities. The full file contains over 80 entities!
| Entity | Table (Schema) | Description |
|---|---|---|
| Asset | irby.Asset |
Base asset type (TPT → TPH) |
| Computer (inherits Asset) | irby.Asset |
Computer‐specific fields (OS, AssetNumber) |
| Employee | irby.Employee |
Company employee registry (added SSN column) |
| FieldOffice | irby.FieldOffice |
Business unit locations |
| DocumentImage | irby.DocumentImage |
Stored scanned documents |
| TimeSheetEntry | irby.TimeSheetEntry |
Employee time entry records |
| LinkUserRole | irby.LinkUserRole |
Junction for user‐role many‑to‑many |
modelBuilder.Entity("IrbyImaging.DomainClasses.Employee", b =>
{
b.Property<Guid>("EmployeeId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
// ← ADDED IN AddSSNColumn Migration
b.Property<string>("LastFourSSN")
.HasColumnType("nvarchar(max)");
b.HasIndex("JdeNumber").IsUnique().HasFilter("[JdeNumber] IS NOT NULL");
b.HasKey("EmployeeId");
b.ToTable("Employee", "irby");
});
Note: The above snippet shows the newly added
LastFourSSNproperty alongside existing columns likeFirstName,LastName,JdeNumber, etc.
🔗 6. Model Relationships
This method configures foreign‑key constraints and navigations:
-
Asset → FieldOffice
b.HasOne("FieldOffice", "FieldOffice") .WithMany("Assets") .HasForeignKey("FieldOfficeId"); -
AssetModel → Manufacturer
b.HasOne("Manufacturer", "Make") .WithMany("Models") .HasForeignKey("MakeId") .OnDelete(DeleteBehavior.Cascade); -
Employee → Department, Job, Role
- Department: optional
- Job: required
- Role: optional
-
Many‑to‑Many
LinkUserRole(User ↔ Role)LinkRolePermission(Role ↔ Permission)
🛠️ 7. Helper Methods & Utilities
-
BuildTargetModel(ModelBuilder modelBuilder)- Core method that recreates the EF model at this migration stage.
- Called by the EF Migrations infrastructure to compare model snapshots.
-
SQL Server Identity Configuration
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);Ensures primary‑key columns use SQL Server IDENTITY columns by default.
🔄 8. How EF Core Migrations Work
- Developer issues:
dotnet ef migrations add AddSSNColumn - EF Core scaffolds:
20240124141838_AddSSNColumn.cs(Up/Down methods)20240124141838_AddSSNColumn.Designer.cs(Model snapshot)
- Developer applies migration:
dotnet ef database update - The Designer file is used to compute diffs for future migrations.
💻 9. Sample Code & Usage
Adding the Migration
# In the Package Manager Console (PMC):
Add-Migration AddSSNColumn
# Or using CLI:
dotnet ef migrations add AddSSNColumn
Applying to Database
# PMC
Update-Database
# CLI
dotnet ef database update
Accessing the New Column
using var context = new IrbyContext();
// Query employees by last 4 SSN
var matches = context.Employees
.Where(e => e.LastFourSSN == "1234")
.ToList();
🎨 10. Mermaid UML Diagram
classDiagram
Asset <|-- Computer
Asset <|-- DeskPhone
Asset <|-- MobileDevice
class Asset {
+Guid Id
+string SerialNumber
+string Status
+DateTimeOffset PurchaseDate
+bool NeedsReview
}
class Computer {
+string AssetNumber
+string CpsNumber
+int OperatingSystemId
}
class Employee {
+Guid EmployeeId
+string FirstName
+string LastName
+string JdeNumber
+string LastFourSSN
}
Asset --> FieldOffice : FieldOfficeId FK
Computer --> OperatingSystem : OperatingSystemId
Employee --> Role : RoleId FK
Employee --> Department : DepartmentId FK
✅ 11. Conclusion
The AddSSNColumn.Designer.cs file is a critical piece of EF Core’s migration engine. It captures the entire state of your database model after adding the LastFourSSN property to the Employee entity.
- Maintains schema versioning for safe, incremental updates.
- Ensures that successive migrations compute only delta changes.
- Automatically managed by EF Core — do not edit manually.
With this documentation, you now have a clear understanding of:
- Why this snapshot exists
- What it configures
- How EF Core uses it during
Add-MigrationandUpdate-Databasecommands
Happy coding! 🚀
ℹ️ For more on EF Core Migrations, see the official docs: https://docs.microsoft.com/ef/core/managing-schemas/migrations/