📚 Migration: 20221031021815_Customer.Designer.cs
Auto‑generated EF Core migration snapshot for the Customer migration
Part of theIrbyImaging.DbContext.Migrationsnamespace
EF Core Version: 5.0.12
🗂 Table of Contents
- Overview & Purpose
- Key Functional Areas
- Dependencies & Technologies
- Data Models Summary
- Relationships & Navigation Properties
- Mermaid ER Diagram
- Usage & Migration Commands
- Sample Code Blocks
- Conclusion
🔍 Overview & Purpose
The Customer.Designer.cs file is an auto‑generated migration snapshot created by Entity Framework Core. It defines the target model at the point in time of the 20221031021815_Customer migration. EF Core uses this snapshot to:
- Compare the existing database schema against the current model.
- Generate SQL operations for schema changes (tables, columns, keys, constraints).
- Enable
dotnet ef database updateto apply migrations in sequence.
This particular migration introduces or synchronizes the Customer entity within the irby schema, along with all other domain classes existing at the time.
🛠️ Key Functional Areas
1. BuildTargetModel Method
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("ProductVersion", "5.0.12")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
// ... Entity configurations appear here ...
#pragma warning restore 612, 618
}
- Purpose: Reconstruct the entire EF Core model snapshot.
- Annotations:
Relational:MaxIdentifierLength: Maximum length of identifiers in the database (e.g., 128 for SQL Server).ProductVersion: EF Core version used to generate this snapshot.SqlServer:ValueGenerationStrategy: Default PK value generation (Identity columns).
2. Entity Configuration & Mapping
For each domain class (e.g., Asset, Customer, Employee, etc.), the snapshot:
- Defines properties with CLR types and database types.
- Sets keys (
HasKey), indexes (HasIndex), and discriminators for inheritance. - Maps each class to a table (often under the
"irby"schema). - Configures relationships (
HasOne,WithMany,OnDelete, etc.). - Uses discriminator columns for table-per-hierarchy mapping (e.g.,
Assetand its subtypes).
⚙ Dependencies & Technologies
| Technology | Version/Detail |
|---|---|
| .NET Core / .NET 5.0 | Cross‑platform runtime |
| Entity Framework Core | 5.0.12 |
| Microsoft SQL Server | Target relational database |
| C# | Source language |
🗃 Data Models Summary
Below is a concise summary of key entities configured in this snapshot (over 40+ domain classes exist; we highlight a few):
| Entity | Table Name | Schema | Primary Key |
|---|---|---|---|
Customer |
Customer | irby | Guid Id |
Asset |
Asset | irby | Guid Id (Discriminator) |
Computer (subtype of Asset) |
Asset | irby | inherits Asset.Id |
Employee |
Employee | irby | Guid Id |
Job |
Job | irby | Guid Id |
FieldOffice |
FieldOffice | irby | Guid Id |
Ticket |
Ticket | irby | Guid Id |
Update |
Update | irby | Guid Id |
| ... | ... | ... | ... |
Entities Added or Changed by This Migration
Customer- Columns:
Id (GUID, PK),CustomerNumber (nvarchar(max)),Name (nvarchar(max)) - Table:
"irby"."Customer"
- Columns:
🔗 Relationships & Navigation Properties
| From Entity | To Entity | Navigation Property | Cardinality | FK Column |
|---|---|---|---|---|
Asset |
FieldOffice |
.FieldOffice |
Many‑to‑One | FieldOfficeId |
Asset |
Employee |
.Owner |
Many‑to‑One | OwnerId |
Asset |
AssetModel |
.Model |
Many‑to‑One | ModelId |
Employee |
Job |
.CurrentJob |
Many‑to‑One | CurrentJobId |
FieldOffice |
Employee |
.Manager etc. |
Many‑to‑One | ManagerId |
Ticket |
Update |
.Updates |
One‑to‑Many | TicketId |
| ... | ... | ... | ... | ... |
🖼 Mermaid ER Diagram
erDiagram
CUSTOMER ||--o{ TICKET : Creates
TICKET ||--o{ UPDATE : Contains
ASSET }o--|| FIELDOFFICE : "Belongs to"
ASSET }o--|| EMPLOYEE : "Owned by"
ASSETMODEL ||--o{ ASSET : "Has models"
EMPLOYEE }o--|| JOB : "Works at"
FIELD OFFICE ||--o{ ASSET : "Hosts assets"
%% Note: Diagram simplified for key relationships
🚀 Usage & Migration Commands
-
Add a new migration (after changing your
DbContextor domain classes):dotnet ef migrations add Customer -
Apply migrations to the database:
dotnet ef database update -
Revert to a previous migration (rollback):
dotnet ef database update <PreviousMigrationName>
💡 Ensure you have the
IrbyImaging.DbContextassembly referenced in your startup project and yourDbContextis configured with the right connection string.
📦 Sample Code Blocks
Invoking BuildTargetModel
This code is auto‑generated and is not intended for manual editing:
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
modelBuilder.Entity("IrbyImaging.DomainClasses.Customer", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("CustomerNumber")
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Customer", "irby");
});
// ... other entities ...
}
Defining a New Domain Class (Before Migration)
public class Customer
{
public Guid Id { get; set; }
public string CustomerNumber { get; set; }
public string Name { get; set; }
}
📝 Conclusion
- This file is an EF Core model snapshot representing the database schema at the time of the
Customermigration. - Do not manually edit the
.Designer.csfile; instead, modify your domain classes orDbContext, then regenerate migrations. - EF Core uses this snapshot to determine what SQL DDL (Data Definition Language) statements are needed to bring your database schema in sync with your code model.
Happy coding! 🎉