🛡️ Migration Designer Documentation: 20230707160813_AddNewSafetyColumns.Designer.cs

Path: IrbyImaging.DbContext/Migrations/20230707160813_AddNewSafetyColumns.Designer.cs
Generated by: Entity Framework Core 7.0.7
Purpose: Defines the target database model after introducing new “safety” flags to several document‑related tables.


📑 Table of Contents

  1. Overview & Purpose
  2. Key Functional Areas
  3. Dependencies & Technologies
  4. View Models & Data Models
  5. Helper Methods & Utilities
  6. Error Handling & Return Types
  7. API Endpoints Overview
  8. Third‑party Integrations
  9. Sample Code Blocks
  10. Entities & New “Safety” Columns
  11. Usage Examples
  12. UML Diagram
  13. Conclusion

1. Overview & Purpose

This auto-generated designer file represents the snapshot of the EF Core model after running the AddNewSafetyColumns migration. Its primary goal is to:

  • Introduce a new boolean column IsSafety to key document tables.
  • Enable filtering and business logic around safety‑related documents and metadata.

By inspecting this file’s BuildTargetModel method, you can see how Entity Framework Core defines tables, columns, relationships, indexes, and new properties.


2. Key Functional Areas

  • 🔄 Schema Snapshot
    Records all tables, columns, types, keys, indexes, relationships.

  • 🛡 New Safety Flags
    Adds IsSafety (bit, non‑nullable, default false) to:

    • DocumentAttribute
    • DocumentCategory
    • DocumentType
    • DocumentImage
    • TempDocumentData
  • 🤝 Relationship Mapping
    Configures navigations between domain classes (e.g., Asset → FieldOffice, Employee → Job).


3. Dependencies & Technologies

Item Version / Package
.NET SDK 7.0.*
Entity Framework Core Microsoft.EntityFrameworkCore 7.0.7
EF Core SQL Server Provider Microsoft.EntityFrameworkCore.SqlServer 7.0.7
EF Core Design Tools (Migrations) Microsoft.EntityFrameworkCore.Design 7.0.7

4. View Models & Data Models

Note: This file only describes data models (the EF Core entity schema).
No view models or DTOs appear here.

  • DomainClasses
    Entities like Asset, DocumentImage, DocumentAttribute, etc.
    Each maps to a table in the irby schema (by default).

5. Helper Methods & Utilities

  • modelBuilder.HasAnnotation(...)
  • SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder)
  • SqlServerPropertyBuilderExtensions.UseIdentityColumn(...)

These are EF Core extensions to configure SQL Server‑specific behaviors:

  • Identity columns (auto‑increment)
  • Max identifier length
  • Product version tracking

6. Error Handling & Return Types

  • Error Handling:
    Not applicable in designer files. No runtime logic.

  • Return Types:
    BuildTargetModel(ModelBuilder modelBuilder) → void


7. API Endpoints Overview

❌ None
This is a database schema snapshot, not a Web API controller.


8. Third‑party Integrations

  • Entity Framework Core
  • Microsoft SQL Server (provider)
  • Value Conversion support (using Microsoft.EntityFrameworkCore.Storage.ValueConversion)

9. Sample Code Blocks

BuildTargetModel Signature

[DbContext(typeof(IrbyContext))]
[Migration("20230707160813_AddNewSafetyColumns")]
partial class AddNewSafetyColumns
{
    protected override void BuildTargetModel(ModelBuilder modelBuilder)
    {
        // Annotations
        modelBuilder
            .HasAnnotation("ProductVersion", "7.0.7")
            .HasAnnotation("Relational:MaxIdentifierLength", 128);

        // SQL Server identity configuration
        SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

        // … entity mappings …
    }
}

Example: Adding a Safety Column

Although designer files don’t show migrationBuilder calls, the corresponding Up migration likely used:

migrationBuilder.AddColumn<bool>(
  name: "IsSafety",
  schema: "irby",
  table: "DocumentAttribute",
  type: "bit",
  nullable: false,
  defaultValue: false);

10. Entities & New “Safety” Columns

Below is a condensed overview of the document‑related entities that now include an IsSafety flag.

Entity Schema Table New Property Column Type Default
DocumentAttribute irby DocumentAttribute IsSafety 🛡 bit false
DocumentCategory irby DocumentCategory IsSafety 🛡 bit false
DocumentType irby DocumentType IsSafety 🛡 bit false
DocumentImage irby DocumentImage IsSafety 🛡 bit false
TempDocumentData irby TempDocumentData IsSafety 🛡 bit false

Tip: Use the IsSafety flag in LINQ queries to segregate safety‑critical documents.


11. Usage Examples

Filter Safety Attributes

var safetyAttributes = context.DocumentAttributes
    .Where(attr => attr.IsSafety)
    .OrderBy(attr => attr.AttributeName)
    .ToList();

Mark a Document as Safety‑Relevant

var doc = await context.DocumentImages.FindAsync(someGuid);
doc.IsSafety = true;
await context.SaveChangesAsync();
var docs = context.DocumentImages
    .Where(d => d.IsLegalDocument || d.IsSafety)
    .ToList();

12. UML Diagram

classDiagram
    class DocumentAttribute {
        +Guid Id
        +string AttributeName
        +bool IsSafety 🛡
    }
    class DocumentCategory {
        +Guid Id
        +string Name
        +bool IsSafety 🛡
    }
    class DocumentType {
        +Guid Id
        +string Type
        +bool IsSafety 🛡
    }
    class DocumentImage {
        +Guid DocumentImageId
        +string FileName
        +bool IsSafety 🛡
    }
    class TempDocumentData {
        +Guid TempDocumentDataId
        +string FileName
        +bool IsSafety 🛡
    }

    DocumentAttribute -- DocumentCategory : belongsTo
    DocumentType -- DocumentCategory : categorizedBy
    DocumentImage -- DocumentType : typedAs
    TempDocumentData -- DocumentType : stagingFor

🔍 Note: Only key relations are shown for brevity.


13. Conclusion

This migration designer file captures the evolved EF Core model after introducing safety‑related flags. With these boolean columns in place:

  • ✅ Filter and classify documents by safety relevance
  • 🔒 Improve compliance and audit workflows
  • 🔄 Maintain single source of truth via EF Core’s migrator

To roll out these changes:

  1. Add migration via dotnet ef migrations add AddNewSafetyColumns
  2. Apply via dotnet ef database update
  3. Use the new IsSafety properties in your application logic!

Happy coding! 🚀