π Documentation: 20230802150235_AddNewColumnToDocumentImageTable.Designer.cs
π Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- File Structure & Annotations
- Key Functional Areas
4.1 Migration Metadata
4.2 Model Snapshot:BuildTargetModel
4.3 Entity Configurations
4.4 Relationships & Navigation - Usage & Examples
- Simplified UML Diagram
- Conclusion
1. Overview & Purpose
What is this file?
This is an auto-generated Entity Framework Core (EF Core) Migration Designer file for the migration named
20230802150235_AddNewColumnToDocumentImageTable. It represents the model snapshot at this point in time.
π― Primary Purpose
- Provide a snapshot of the entire EF Core model (entities, properties, relationships) after applying the AddNewColumnToDocumentImageTable migration.
- Enable EF Core to calculate and apply subsequent migrations by comparing current model vs. this snapshot.
Note: You typically do not edit designer files by hand.
2. Dependencies & Technologies
| Dependency | Purpose |
|---|---|
Microsoft.EntityFrameworkCore |
Core EF APIs for ModelBuilder, Migrations, Metadata |
Microsoft.EntityFrameworkCore.Migrations |
Supports migration building and data seeding |
Microsoft.EntityFrameworkCore.Metadata |
Defines annotations, conventions, mapping strategies |
Microsoft.EntityFrameworkCore.Storage.ValueConversion |
Value converters (e.g. string β enum) |
| C# 10 / .NET 7 | Language & runtime for code generation |
3. File Structure & Annotations
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace IrbyImaging.DbContext.Migrations
{
[DbContext(typeof(IrbyContext))]
[Migration("20230802150235_AddNewColumnToDocumentImageTable")]
partial class AddNewColumnToDocumentImageTable
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
// ... entire model snapshot ...
}
}
}
[DbContext]attribute links this snapshot to yourIrbyContext.[Migration(...)]specifies the unique timestamp-based identifier.BuildTargetModeloverrides define the database schema.
4. Key Functional Areas
4.1 Migration Metadata
- ProductVersion
modelBuilder .HasAnnotation("ProductVersion", "7.0.7") .HasAnnotation("Relational:MaxIdentifierLength", 128); - UseIdentityColumns
Activates SQL Server identity behavior for auto-generated keys.SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
4.2 Model Snapshot: BuildTargetModel
- Purpose: Reflects the entire EF Core model (all
DbSet<T>entities) after this migration. - Mechanism:
- Entity declarations with
modelBuilder.Entity("Namespace.Type", b => { ... }). - Property mappings:
.Property<type>("Name") - Keys & Indices:
.HasKey(),.HasIndex() - Table mapping:
.ToTable("TableName", "schema") - Relationships:
.HasOne(...).WithMany(...).HasForeignKey(...)
- Entity declarations with
4.3 Entity Configurations
Below is a representative sampleβthe file configures dozens of entities. Hereβs the snippet for the DocumentImage table (the target of this migration):
modelBuilder.Entity("IrbyImaging.DomainClasses.DocumentImage", b =>
{
b.Property<Guid>("DocumentImageId")
.HasColumnType("uniqueidentifier");
// π NEW COLUMN (added by this migration)
b.Property<string>("NewColumnName")
.HasColumnType("nvarchar(max)");
// Existing columns
b.Property<string>("FileName").HasColumnType("nvarchar(max)");
b.Property<byte[]>("ImageContents").HasColumnType("varbinary(max)");
b.Property<bool>("IsDeleted").HasColumnType("bit");
// ... many others ...
b.HasKey("DocumentImageId")
.HasName("PrimaryKey_DocumentImageId");
b.ToTable("DocumentImage", "irby");
});
π Key Concepts
.Property<>()β maps a CLR property to a database column..HasColumnType()β specifies exact SQL type..HasKey()β configures the primary key..ToTable()β sets schema & table name.
4.4 Relationships & Navigation
All associations between domain classes are rebuilt in this snapshot. Example:
modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b =>
{
b.HasOne("IrbyImaging.DomainClasses.Employee", "Owner")
.WithMany("Assets")
.HasForeignKey("OwnerId");
// β¦
});
- OneβtoβMany:
.HasOne(...).WithMany(...) - Cascade delete rules and required constraints appear in
.OnDelete(DeleteBehavior.Cascade)and.IsRequired()calls.
5. Usage & Examples
5.1 Common Commands
- Add a new migration
dotnet ef migrations add AddNewColumnToDocumentImageTable - Update database
dotnet ef database update
5.2 What Happens Under the Hood
- EF Core generates two files:
20230802150235_AddNewColumnToDocumentImageTable.cs(migration operations)- This file:
.Designer.cs(model snapshot)
- When you call
update, EF compares the current model (your code-first classes +OnModelCreating) against this snapshot to see what SQL operations to run. - Designer file ensures EF knows the baseline schema.
6. Simplified UML Diagram
Below is a simplified classβdiagram fragment showing how entities relate. Only key parts are illustrated:
+----------------+ 1 * +----------------+
| Employee |----------------------| Asset |
+----------------+ Assets +----------------+
| - EmployeeId | | - Id |
| - FirstName | | - SerialNumber|
| - LastName | | - ModelId |
+----------------+ +----------------+
Employeehas manyAssetAssetreferencesEmployeeviaOwnerId
(The real model has dozens of tables; this is just an illustrative snippet.)
7. Conclusion
This Designer file is a critical piece of EF Core migrations, capturing your entire model at a given migration point.
- βοΈ Do not edit manually β changes will be lost.
- β Use EF Core CLI or Package Manager Console to generate and apply migrations.
- π§ Understand BuildTargetModel to troubleshoot advanced scenarios (e.g., customizing comments, schemas, conventions).
Thank you for reading! π If you need to add, rollback, or inspect migrations, always refer to both the operations file (.cs) and its Designer snapshot.