IrbyImaging.DbContext Migration Designer: 20221102175711_NewCoulmnForDocumentAttribute.Designer.cs 🚀
📑 Table of Contents
- Overview & Purpose
- File Structure & EF Core Migration Basics
- BuildTargetModel Method
- Key Functional Areas
4.1 Model Annotations
4.2 Entity Configurations
• DocumentAttribute
• DocumentCategory
• DocumentImage
• DocumentType
• Other Entities (Overview)
4.3 Relationships & Navigations - UML Diagram – Document Domain 📈
- Dependencies & Technologies 🛠️
- Error Handling & Return Types 🤖
- Third‑Party Integrations 🔌
- Sample Usage & Code Snippets 📂
- Conclusion 🎯
1. Overview & Purpose
The file
20221102175711_NewCoulmnForDocumentAttribute.Designer.cs
is an auto‑generated Entity Framework Core model snapshot for the migration named NewCoulmnForDocumentAttribute. EF Core uses it to understand the target database schema after this migration is applied.
Important:
• Do not manually edit this file—changes are overwritten.
• It lives alongside the corresponding migration (.cs) that defines theUp()/Down()steps.
2. File Structure & EF Core Migration Basics
IrbyImaging.DbContext/
└── Migrations/
├── 20221102175711_NewCoulmnForDocumentAttribute.cs
└── 20221102175711_NewCoulmnForDocumentAttribute.Designer.cs
- Migration (
.cs): Contains schema changes (Up/Down). - Designer (
.Designer.cs): Contains theBuildTargetModelmethod describing the entire EF model at this point in time.
3. BuildTargetModel Method
[DbContext(typeof(IrbyContext))]
[Migration("20221102175711_NewCoulmnForDocumentAttribute")]
partial class NewCoulmnForDocumentAttribute
{
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);
// … dozens of Entity() calls configuring tables, columns, keys, relationships …
#pragma warning restore 612, 618
}
}
- Global Annotations set up max identifier length, EF Core version, and SQL Server identity defaults.
- Each call to
modelBuilder.Entity("Namespace.ClassName", b => { … })configures a table, its columns, keys, indexes and more. - Relationship mappings appear at the bottom, linking foreign keys and navigation properties.
4. Key Functional Areas
4.1 Model Annotations
| Annotation | Meaning |
|---|---|
| Relational:MaxIdentifierLength = 128 | Max length of table/column names |
| ProductVersion = 5.0.12 | EF Core version |
| SqlServer:ValueGenerationStrategy = IdentityColumn | Default key strategy for SQL Server identity columns |
4.2 Entity Configurations
Below are the Document‑related entities (others follow the same pattern).
DocumentAttribute
| Property | CLR Type | Column Type | Notes |
|---|---|---|---|
| Id | Guid | uniqueidentifier | PK, generated on add |
| AddedBy | string | nvarchar(max) | |
| AddedDate | DateTime | datetime2 | |
| AttributeName | string | nvarchar(max) | |
| AttributeType | int | int | Enum or code for data type |
| DocumentType | string | nvarchar(max) | FK via string to DocumentType.Type |
| IsAvailable | bool | bit | |
| IsDeleted | bool | bit | Soft‑delete flag |
| IsMultiValue | bool | bit | Multiple values allowed |
| IsRequired | bool | bit | Mandatory field |
| LinkCustomerData | bool | bit | |
| LinkEmployeeData | bool | bit | |
| LinkJobData | bool | bit | |
| ModifiedBy | string | nvarchar(max) | |
| ModifiedDate | DateTime | datetime2 | |
| Values | string | nvarchar(max) | Serialized list of allowed values |
modelBuilder.Entity("IrbyImaging.DomainClasses.DocumentAttribute", b => {
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("AttributeName").HasColumnType("nvarchar(max)");
// … other properties …
b.HasKey("Id");
b.ToTable("DocumentAttribute", "irby");
});
DocumentCategory
| Property | CLR Type | Column Type | Notes |
|---|---|---|---|
| Id | Guid | uniqueidentifier | PK |
| Name | string | nvarchar(max) | |
| Description | string | nvarchar(max) | |
| IsAvailable | bool | bit | |
| IsDeleted | bool | bit | |
| AddedBy / Date / ModifiedBy / Date | … | … | Audit fields |
modelBuilder.Entity("IrbyImaging.DomainClasses.DocumentCategory", b => {
b.HasKey("Id");
b.ToTable("DocumentCategory", "irby");
});
DocumentImage
Stores binary image data, OCR results, metadata, page counts, etc.
modelBuilder.Entity("IrbyImaging.DomainClasses.DocumentImage", b => {
b.Property<Guid>("DocumentImageId").HasColumnType("uniqueidentifier");
b.Property<byte[]>("ImageContents").HasColumnType("varbinary(max)");
b.Property<byte[]>("ImageOCRContents").HasColumnType("varbinary(max)");
b.Property<string>("ImageOCRText").HasColumnType("nvarchar(max)");
b.Property<int>("Page").HasColumnType("int");
b.HasKey("DocumentImageId");
b.ToTable("DocumentImage", "irby");
});
DocumentType
| Property | CLR Type | Column Type | Notes |
|---|---|---|---|
| Id | Guid | uniqueidentifier | PK |
| Type | string | nvarchar(max) | Unique document type |
| DocumentCategory | string | nvarchar(max) | Category name as string |
modelBuilder.Entity("IrbyImaging.DomainClasses.DocumentType", b => {
b.HasKey("Id");
b.ToTable("DocumentType", "irby");
});
Other Entities (Overview)
This Designer snapshot configures over 40 domain classes, among them:
- Asset & subtypes (Computer, MobileDevice, Dock, …)
- AssetModel, AssetHistory, Manufacturer, OperatingSystem
- Employee, FieldOffice, Job, ODS staging tables
- Ticket & Update
- BillingInvoice, CarrierType & Details
- CovidTestData, Customer, GLTypeDetail, GeneralLedger, …
Tip: Search your IDE for
modelBuilder.Entity("IrbyImaging.DomainClasses.to explore each.
4.3 Relationships & Navigations
At the bottom of BuildTargetModel, EF Core wires up foreign keys and navigations:
// Example: Employee → Job (CurrentJobId)
modelBuilder.Entity("IrbyImaging.DomainClasses.Employee", b => {
b.HasOne("IrbyImaging.DomainClasses.Job", "CurrentJob")
.WithMany("Employees")
.HasForeignKey("CurrentJobId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
- One‑to‑Many:
Job→Employees - One‑to‑One (optional):
FieldOffice.Manager→Employee - Inheritance:
Assetbase type with discriminator for subtypes
5. UML Diagram – Document Domain 📈
@startuml
title “Document Domain UML”
class DocumentCategory {
+ Guid Id
+ string Name
+ bool IsAvailable
}
class DocumentType {
+ Guid Id
+ string Type
+ bool IsAvailable
}
class DocumentAttribute {
+ Guid Id
+ string AttributeName
+ int AttributeType
+ string DocumentType
}
class DocumentImage {
+ Guid DocumentImageId
+ byte[] ImageContents
+ int Page
}
DocumentCategory "1" --* "0..*" DocumentType : has
DocumentType "1" --* "0..*" DocumentAttribute : describes
DocumentType "1" ..> "0..*" DocumentImage : attached to
@enduml
Paste into a PlantUML tool to render a diagram.
6. Dependencies & Technologies 🛠️
- .NET 5.0
- Entity Framework Core 5.0.12
- SQL Server (Identity columns)
- IrbyImaging.DbContext (
IrbyContext)
No additional NuGet packages are referenced in this snapshot.
7. Error Handling & Return Types 🤖
- This is a design‑time snapshot: No runtime logic, error handling or return types.
- Runtime errors (e.g., migrations mismatch) surface when applying migrations via EF Core CLI.
8. Third‑Party Integrations 🔌
None. This file is purely EF Core infrastructure—no external services or libraries.
9. Sample Usage & Code Snippets 📂
9.1 Applying Migrations
# Apply this and all pending migrations
dotnet ef database update
9.2 Inspecting Entity Model
using var context = new IrbyContext();
var entities = context.Model.GetEntityTypes()
.Where(e => e.ClrType.Name.Contains("Document"))
.Select(e => e.Name);
Console.WriteLine("Document Entities:");
foreach (var name in entities)
Console.WriteLine($"- {name}");
10. Conclusion 🎯
- This Designer file is an EF Core snapshot for the NewCoulmnForDocumentAttribute migration.
- It represents the complete database schema model at that point.
- Never hand‑edit—use
dotnet ef migrations add/updateto modify. - Keep it under source control to ensure repeatable and reliable schema updates.
Happy coding! ✨
Whenever you need to add or modify a column on DocumentAttribute (or any other table), scaffold a new migration and let EF Core regenerate this snapshot.