π¦ Migration: ChangeFieldOfficeTable
File: IrbyImaging.DbContext/Migrations/20220516185008_ChangeFieldOfficeTable.Designer.cs
Generated: 05β17β2022 by kvamshi
π Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- BuildTargetModel Method Explained
- Data Models & Entity Configurations
- Relationships & Constraints
- UML Diagram
- How to Use This Migration
- Sample Code Blocks & Usage
- Conclusion
π 1. Overview & Purpose
This Designer file is an auto-generated snapshot of your EF Core model at the point of the ChangeFieldOfficeTable migration.
- What is it?
- A model snapshot that
MigrationBuilderuses to know how your schema should look after applying this migration.
- A model snapshot that
- Why is it here?
- EF Core stores two parts of a migration:
- Up/Down logic (
.csfile) - Model snapshot (
.Designer.csfile)
- Up/Down logic (
- This ensures EF can detect future changes reliably.
- EF Core stores two parts of a migration:
π§ 2. Dependencies & Technologies
- .NET 5.0
- EntityFrameworkCore (v5.0.12)
Microsoft.EntityFrameworkCoreMicrosoft.EntityFrameworkCore.MigrationsMicrosoft.EntityFrameworkCore.MetadataMicrosoft.EntityFrameworkCore.InfrastructureMicrosoft.EntityFrameworkCore.Storage.ValueConversion
- SQL Server (
SqlServerValueGenerationStrategy.IdentityColumn)
π― 3. Key Functional Areas
- Configuration of all domain entities and their properties.
- Definition of keys, indexes, table schemas, discriminators (for inheritance).
- Relationships: foreign keys, navigation properties.
- Schema specification (
.HasAnnotation("Relational:MaxIdentifierLength", 128)&.ToTable("...", "irby")).
π 4. BuildTargetModel Method Explained
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);
// ... many Entity <-> Table mappings ...
#pragma warning restore 612, 618
}
- ModelBuilder: the EF Core fluent API entry point for configuring your domain classes.
- Each
modelBuilder.Entity("Namespace.ClassName", b => { ... })block:- b.Property<T>("PropName") β maps a CLR property to a DB column.
- b.HasKey("Id") β primary key.
- b.HasIndex("SomeProp") β index (with optional
.IsUnique()). - b.ToTable("TableName", "irby") β specify table & schema.
- b.HasDiscriminator<T>("Discriminator") β tableβperβhierarchy inheritance.
π 5. Data Models & Entity Configurations
β¨ FieldOffice Table Changes
This migrationβs focus was the FieldOffice table.
| Column | Type | Nullable | Constraints |
|---|---|---|---|
| Id | uniqueidentifier |
No | PK, value generated on add |
| BusinessUnitName | nvarchar(max) |
Yes | β |
| BusinessUnitNumber | nvarchar(max) |
Yes | β |
| JdeNumber | nvarchar(450) |
Yes | Unique index (.HasIndex("JdeNumber").IsUnique()) |
| ManagerId | uniqueidentifier |
Yes | FK β Employee(Id) |
| Name | nvarchar(max) |
Yes | β |
| ProjectManagerId | uniqueidentifier |
Yes | FK β Employee(Id) |
| SuperintendentId | uniqueidentifier |
Yes | FK β Employee(Id) |
modelBuilder.Entity("IrbyImaging.DomainClasses.FieldOffice", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("BusinessUnitName").HasColumnType("nvarchar(max)");
b.Property<string>("BusinessUnitNumber").HasColumnType("nvarchar(max)");
b.Property<string>("JdeNumber").HasColumnType("nvarchar(450)");
b.Property<Guid?>("ManagerId").HasColumnType("uniqueidentifier");
b.Property<string>("Name").HasColumnType("nvarchar(max)");
b.Property<Guid?>("ProjectManagerId").HasColumnType("uniqueidentifier");
b.Property<Guid?>("SuperintendentId").HasColumnType("uniqueidentifier");
b.HasKey("Id");
b.HasIndex("JdeNumber").IsUnique().HasFilter("[JdeNumber] IS NOT NULL");
b.HasIndex("ManagerId");
b.HasIndex("ProjectManagerId");
b.HasIndex("SuperintendentId");
b.ToTable("FieldOffice", "irby");
});
π Other Key Entities (Summary)
Below is a sampling; the file configures 25+ tables.
- Asset Hierarchy
- Base:
Asset (Discriminator="Asset") - Derived:
Computer,DeskPhone,MobileDevice,Monitor,OfficePrinter,Dock,Printer,SafetyEquipment,NetworkEquipment
- Base:
- AssetModel & AssetModelDetail
- Employee, Job, FieldOffice
- BillingInvoice, **CarrierType
/CarrierTypeDetail` - CovidTestData, DocumentImage, TempDocumentData, IPMMigration
- GLTypeDetail, GeneralLedger
- Ticket & Update
- ODS_Staging tables:
ODSEmployee,ODSJob
π 6. Relationships & Constraints
- One-to-Many:
- FieldOffice β Asset (
FieldOffice.Assets) - Employee β Asset (
Employee.Assets) - AssetModel β Asset (
AssetModelβAsset) - Job β Employee (
Job.Employees) - Ticket β Update (
Ticket.Updates)
- FieldOffice β Asset (
- Many-to-One:
- Asset β FieldOffice, AssetModel, Employee
- FieldOffice β Employee (Manager, ProjectManager, Superintendent)
- Cascade Deletes: configured for required FKs
modelBuilder.Entity("IrbyImaging.DomainClasses.FieldOffice", b =>
{
b.HasOne("IrbyImaging.DomainClasses.Employee", "Manager")
.WithMany()
.HasForeignKey("ManagerId");
// β¦ similarly for ProjectManager & Superintendent
});
π 7. UML Diagram
erDiagram
FIELD_OFFICE ||--o{ ASSET : "hosts"
EMPLOYEE ||--o{ ASSET : "owns"
ASSET_MODEL ||--o{ ASSET : "models"
FIELD_OFFICE }|..|| EMPLOYEE : Manager
FIELD_OFFICE }|..|| EMPLOYEE : ProjectManager
FIELD_OFFICE }|..|| EMPLOYEE : Superintendent
TICKET ||--o{ UPDATE : "updates"
π 8. How to Use This Migration
- Apply to your database:
dotnet ef database update 20220516185008_ChangeFieldOfficeTable - Rollback to previous migration:
dotnet ef database update <PreviousMigrationName> - Inspect your schema changes:
- Use SQL Server Management Studio or
dotnet ef migrations script.
- Use SQL Server Management Studio or
π‘ 9. Sample Code Blocks & Usage
Adding a New FieldOffice in C#
using (var context = new IrbyContext())
{
var office = new FieldOffice {
BusinessUnitName = "Engineering",
BusinessUnitNumber = "ENG-001",
JdeNumber = "100234",
Name = "North Field",
ManagerId = managerGuid
};
context.FieldOffices.Add(office);
context.SaveChanges();
}
Querying Assets by FieldOffice
var assetsInNorthField = context.Assets
.Include(a => a.FieldOffice)
.Where(a => a.FieldOffice.JdeNumber == "100234")
.ToList();
π 10. Conclusion
π This Designer file is a snapshot of your EF Core model postβmigration.
- It ensures consistency for future migrations.
- Any change in your domain classes will generate a new
.Designer.csto reflect updates. - Tip: Donβt manually edit this file; let EF Core maintain it.
Happy coding! β¨