🚀 Migration Snapshot: AddFileandJobName.Designer.cs
Assembly: IrbyImaging.DbContext
Namespace:IrbyImaging.DbContext.Migrations
Created/Modified: 03‑31‑2022 by kvamshi
File:20220303192042_AddFileandJobName.Designer.cs
📑 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Migration Context
- BuildTargetModel Method
- Key Changes: FileName & JobName
- Entity Configurations
- Relationships & Navigation
- Using EF Core Migrations
- Sample Code & Usage
- UML Class Diagram 🎨
- Conclusion
1. Overview & Purpose
This auto-generated .Designer.cs file is the model snapshot for the EF Core migration named 20220303192042_AddFileandJobName.
It captures the entire database schema after applying that migration. EF Core uses it to compute diffs for future migrations.
Why you should care
- 🔒 Do not edit manually
- 🔄 Serves as a baseline for subsequent migrations
- 📦 Reflects all entities, properties, keys, indexes & relationships
2. Dependencies & Technologies
| Technology / Package | Version | Role |
|---|---|---|
| Microsoft.EntityFrameworkCore | 5.0.12 | ORM Core |
| Microsoft.EntityFrameworkCore.SqlServer | 5.0.12 | SQL Server provider |
| Microsoft.EntityFrameworkCore.Tools | 5.0.12 | CLI tooling (migrations, scaff.) |
| .NET | 5.0 | Target framework |
3. Migration Context
[DbContext(typeof(IrbyContext))]
[Migration("20220303192042_AddFileandJobName")]
partial class AddFileandJobName : Migration
{
protected override void BuildTargetModel(ModelBuilder modelBuilder) { /* … */ }
}
- DbContext:
IrbyContext - Migration ID:
20220303192042_AddFileandJobName - Role: Defines the snapshot of your EF Core model.
4. 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 registrations follow …
#pragma warning restore 612, 618
}
- Annotations set global conventions (table naming, identifier length, versioning).
- Each
modelBuilder.Entity("…", b => { … })call configures one CLR type → DB table mapping.
5. Key Changes: FileName & JobName
This migration’s core purpose is to add two new columns — FileName and JobName — to two major entities:
| Entity | New Columns | Column Type |
|---|---|---|
| BillingInvoice | FileName, JobName | nvarchar(max) |
| DocumentImage | FileName, JobName | nvarchar(max) |
BillingInvoice Snippet
modelBuilder.Entity("IrbyImaging.DomainClasses.BillingInvoice", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd();
// ← Newly added
b.Property<string>("FileName")
.HasColumnType("nvarchar(max)");
b.Property<string>("JobName")
.HasColumnType("nvarchar(max)");
// … other props …
b.HasKey("Id");
b.ToTable("BillingInvoice", "irby");
});
DocumentImage Snippet
modelBuilder.Entity("IrbyImaging.DomainClasses.DocumentImage", b =>
{
b.Property<Guid>("DocumentImageId")
.HasColumnType("uniqueidentifier");
// ← Newly added
b.Property<string>("FileName")
.HasColumnType("nvarchar(max)");
b.Property<string>("JobName")
.HasColumnType("nvarchar(max)");
// … other props …
b.HasKey("DocumentImageId")
.HasName("PrimaryKey_DocumentImageId");
b.ToTable("DocumentImage", "irby");
});
6. Entity Configurations
📌 Only a subset is shown. The model snapshot includes 20+ domain classes.
Assets & Inheritance (TPH Pattern)
| Discriminator | Entity | Table Schema |
|---|---|---|
Asset |
Asset |
irby.Asset |
Computer |
Computer (derives) |
irby.Asset |
DeskPhone |
DeskPhone (derives) |
irby.Asset |
MobileDevice |
MobileDevice (derives) |
irby.Asset |
| … others … | … | irby.Asset |
Sample: AssetModel
modelBuilder.Entity("IrbyImaging.DomainClasses.AssetModel", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<string>("Category")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsAvailableOption")
.HasColumnType("bit");
b.Property<int>("MakeId")
.HasColumnType("int");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.Property<string>("Type")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("MakeId");
b.ToTable("AssetModel", "irby");
});
7. Relationships & Navigation
How they’re wired up
- HasOne…WithMany…HasForeignKey
- Navigation properties registered via
b.Navigation("…")
Example: Asset → AssetModel
modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b =>
{
b.HasOne("IrbyImaging.DomainClasses.AssetModel", "Model")
.WithMany()
.HasForeignKey("ModelId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Model");
});
8. Using EF Core Migrations
- Add/Migrate
dotnet ef migrations add AddFileandJobName - Apply to DB
dotnet ef database update - Inspect Snapshot
- Location:
/Migrations/20220303192042_AddFileandJobName.Designer.cs - Reflects schema after migration.
- Location:
9. Sample Code & Usage
Save a new BillingInvoice
using var ctx = new IrbyContext();
var invoice = new BillingInvoice
{
CarrierId = Guid.NewGuid(),
Charge = 250.00m,
FileName = "inv_20220331.pdf",
JobName = "Warehouse Upgrade",
AddedBy = "john.doe",
AddedDate = DateTime.Now
};
ctx.BillingInvoices.Add(invoice);
ctx.SaveChanges();
Query DocumentImages by JobName
var results = ctx.DocumentImages
.Where(d => d.JobName == "Warehouse Upgrade")
.Select(d => new { d.FileName, d.JobName, d.Page })
.ToList();
10. UML Class Diagram 🎨
classDiagram
%% Inheritance
Asset <|-- Computer
Asset <|-- MobileDevice
Asset <|-- DeskPhone
%% Entities & Relationships
Asset : Guid Id
Asset : string SerialNumber
Computer : string AssetNumber
Computer : int OperatingSystemId
AssetModel : int Id
AssetModel : string Name
AssetModel --> Asset : 1-to-many
Manufacturer --> AssetModel : 1-to-many
BillingInvoice : Guid Id
BillingInvoice : string FileName
BillingInvoice : string JobName
DocumentImage : Guid DocumentImageId
DocumentImage : string FileName
DocumentImage : string JobName
This is a simplified excerpt of the full domain model.
11. Conclusion
✨ The AddFileandJobName.Designer.cs snapshot is your EF Core source of truth after adding FileName and JobName columns.
- Tip: Never hand-edit this file—use EF Core CLI or Package Manager Console.
- Up Next: Review the corresponding
Up()/Down()methods inAddFileandJobName.csfor the actual SQL DDL operations.
Happy coding! 🚀