πŸ“š Documentation: 20230614163408_AddBlobNameColumn.Designer.cs

File Path:
IrbyImaging.DbContext/Migrations/20230614163408_AddBlobNameColumn.Designer.cs


πŸ“‘ Table of Contents

  1. Overview & Purpose
  2. Migration Context
  3. BuildTargetModel Method
  4. Entity Configurations
    4.1 Asset & Inheritance Hierarchy
    4.2 DocumentImage & BlobName Column
    4.3 Other Major Entities (Summary)
  5. Relationships & Navigation Properties
  6. Indexes & Constraints
  7. UML Diagram
  8. Dependencies & Technologies
  9. Usage Example
  10. Generating & Applying Migrations
  11. Conclusion

1. Overview & Purpose

πŸš€ Purpose
This designer file is auto-generated by Entity Framework Core (EF Core) as part of the AddBlobNameColumn migration (20230614163408). It provides a snapshot of the target database model after the migration is applied.

πŸ” What It Does

  • Defines the complete EF Core model via the BuildTargetModel(ModelBuilder modelBuilder) method.
  • Configures entities, properties, schemas, relationships, indexes, and discriminators.
  • Highlights the addition of a new column, BlobName, to the DocumentImage table.

2. Migration Context

  • Migration Name: 20230614163408_AddBlobNameColumn
  • DbContext: IrbyContext
  • EF Core Version: 5.0.12
  • Provider: Microsoft SQL Server (SqlServer:ValueGenerationStrategy = IdentityColumn)

Note: This file is not hand‐edited. Instead, EF Core scaffolds it when you run

dotnet ef migrations add AddBlobNameColumn

3. 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 follow ...
    
    #pragma warning restore 612, 618
}
  • Annotations: Set max identifier length, product version, and default value generation strategy.
  • Entity Registration: Calls modelBuilder.Entity(...) for each domain class.

4. Entity Configurations

4.1 Asset & Inheritance Hierarchy πŸ—ƒοΈ

EF Core uses Table Splitting and TPT/TPC‐style mapping with a discriminator column named Discriminator.

Base Type Discriminator Value Derived Type
Asset "Asset" – (base)
Asset "Computer" Computer
Asset "DesktopPhone" DeskPhone
Asset "Dock" Dock
Asset "MobileDevice" MobileDevice
Asset "Monitor" Monitor
Asset "NetworkEquipment" NetworkEquipment
Asset "OfficePrinter" OfficePrinter
Asset "Printer" Printer
Asset "SafetyEquipment" SafetyEquipment

Common Asset Properties:

Property Type Required? Notes
Id Guid βœ” PK, Identity
Category string βœ” nvarchar(max)
ModelId int βœ” FK β†’ AssetModel
PurchaseDate DateTimeOffset βœ”
SerialNumber string βœ”
Status string βœ” nvarchar(max)
NeedsReview bool βœ” bit
Notes string – nvarchar(max)
OwnerId Guid? – FK β†’ Employee
FieldOfficeId Guid? – FK β†’ FieldOffice

Derived types add their own specialized properties (e.g., Imei, PhoneNumber for MobileDevice).


4.2 DocumentImage & BlobName Column πŸ“¦

This migration introduces the BlobName column to the DocumentImage table (schema: irby).

modelBuilder.Entity("IrbyImaging.DomainClasses.DocumentImage", b =>
{
    b.ToTable("DocumentImage", "irby");

    // Primary Key
    b.Property<Guid>("DocumentImageId")
        .HasColumnType("uniqueidentifier")
        .ValueGeneratedOnAdd();
    
    // Newly added column:
    b.Property<string>("BlobName")
        .HasColumnType("nvarchar(max)");
    
    // Other existing properties...
    b.Property<string>("FileName")
        .HasColumnType("nvarchar(max)");
    b.Property<string>("ContentType")
        .HasColumnType("nvarchar(max)");
    b.Property<byte[]>("ImageContents")
        .HasColumnType("varbinary(max)");
    b.Property<byte[]>("ImageOCRContents")
        .HasColumnType("varbinary(max)");
    b.Property<string>("ImageOCRText")
        .HasColumnType("nvarchar(max)");
    // … (many more)
    
    b.HasKey("DocumentImageId").HasName("PrimaryKey_DocumentImageId");
});

Table: irby.DocumentImage

Column Type Notes
DocumentImageId uniqueidentifier PK
BlobName nvarchar(max) New
FileName nvarchar(max)
ContentType nvarchar(max)
ImageContents varbinary(max)
ImageOCRContents varbinary(max)
ImageOCRText nvarchar(max)
… … …

4.3 Other Major Entities (Summary)

This migration snapshot contains 40+ domain entities. Below are a few highlights; consult the code for the full list:

Entity Table Schema Comments
AssetHistory AssetHistory irby Logs changes to assets
AssetModel AssetModel irby Defines makes and models
CarrierType CarrierType irby Lists types of carriers
CovidTestData CovidTestData irby Stores COVID test results & images
Customer Customer irby Customer master data
DocumentCategory DocumentCategory irby Document type categories
Employee Employee irby Company employees
FieldOffice FieldOffice irby Construction site offices
GeneralLedger GeneralLedger irby GL Codes
Job Job irby Project or job records
ODS_Employee_Staging ODS_Employee_Staging irby ERP staging for employees
ODS_Jobs_Staging ODS_Jobs_Staging irby ERP staging for jobs
Ticket Ticket irby Support or service tickets
Update Update irby Ticket updates (FK β†’ Ticket)
… … … …

5. Relationships & Navigation Properties πŸ”—

  • One‐to‐Many:
    • Asset β†’ AssetHistory
    • AssetModel β†’ AssetModelDetail
    • FieldOffice β†’ Assets
    • Employee β†’ Assets, Updates
    • Ticket β†’ Updates
  • Many‐to‐One (FKs):
    • Asset.ModelId β†’ AssetModel.Id
    • Asset.OwnerId β†’ Employee.Id
    • Asset.FieldOfficeId β†’ FieldOffice.Id
  • Unique Index / Alternate Keys:
    • Employee.JdeNumber (unique)
    • FieldOffice.JdeNumber (unique)
    • Job.JdeNumber (unique)

Navigation properties are defined to facilitate LINQ queries, e.g.,

public class Asset
{
    public Guid Id { get; set; }
    public AssetModel Model { get; set; }
    public Employee Owner { get; set; }
    public FieldOffice FieldOffice { get; set; }
    public ICollection<AssetHistory> History { get; set; }
}

6. Indexes & Constraints πŸ”‘

Table Index / Constraint Columns Type
Asset PK Id Primary
Asset IX_Asset_ModelId ModelId Index
Employee UQ_Employee_JdeNumber JdeNumber Unique
FieldOffice UQ_FieldOffice_JdeNumber JdeNumber Unique
MobileDevice UQ_MobileDevice_Imei Imei Unique
DocumentImage PK_PrimaryKey_DocumentImageId DocumentImageId Primary
Ticket PK Id Primary
Update FK_Update_TicketId (Cascade Delete) TicketId Foreign
… … … …

7. UML Diagram 🧩

classDiagram
    class Asset {
        +Guid Id
        +string Category
        +int ModelId
        +DateTimeOffset PurchaseDate
        +string SerialNumber
        +bool NeedsReview
        +string Status
        +string Notes
    }
    Asset <|-- Computer
    Asset <|-- MobileDevice
    Asset <|-- DeskPhone
    Asset <|-- Monitor
    
    class DocumentImage {
        +Guid DocumentImageId
        +string BlobName
        +string FileName
        +string ContentType
        +byte[] ImageContents
        +byte[] ImageOCRContents
    }
    class AssetModel {
        +int Id
        +string Name
    }
    class Employee {
        +Guid Id
        +string FirstName
    }
    
    AssetModel "1" -- "*" Asset : "Assets"
    Employee    "1" -- "*" Asset : "Assets"
    Asset      "*" -- "*" DocumentImage : "References?"

8. Dependencies & Technologies πŸ› οΈ

  • .NET 5.0
  • EntityFrameworkCore 5.0.12
  • Microsoft.EntityFrameworkCore.SqlServer
  • C# 9.0
  • SQL Server (Identity columns, nvarchar(max), varbinary(max), datetimeoffset)

9. Usage Example πŸƒβ€β™‚οΈ

Once you have this migration in your project:

# Scaffold the migration (already done)
dotnet ef migrations add AddBlobNameColumn

# Apply to database
dotnet ef database update

In your C# code, you can now reference the new BlobName:

var doc = new DocumentImage {
    FileName = "invoice.pdf",
    BlobName = "invoices/2023/06/invoice.pdf",
    ContentType = "application/pdf",
    ImageContents = myByteArray
};
context.DocumentImages.Add(doc);
await context.SaveChangesAsync();

10. Generating & Applying Migrations βš™οΈ

  1. Add Column in Domain Model (if you track model):
    public class DocumentImage {
        public Guid DocumentImageId { get; set; }
        public string BlobName { get; set; }    // New property
        // ...
    }
    
  2. Create Migration:
    dotnet ef migrations add AddBlobNameColumn
    
  3. Review Generated Files:
    • 20230614163408_AddBlobNameColumn.cs
    • 20230614163408_AddBlobNameColumn.Designer.cs
  4. Apply to Database:
    dotnet ef database update
    

11. Conclusion 🎯

This Designer snapshot is crucial for EF Core to understand your target database model. It captures:

  • The addition of the BlobName column to the DocumentImage table.
  • The full entity graph, inheritance hierarchies, navigations, indexes, and schema details.

By maintaining this file alongside your migrations, EF Core can reliably apply, rollback, and scaffold future migrations as your domain model evolves. Happy coding! πŸš€