πŸ“„ IrbyImaging.DbContext.Migrations/20240605163427_AddImagingTypes2.cs Documentation


πŸ“‘ Table of Contents

  1. Overview & Purpose
  2. Key Functional Areas
  3. Dependencies & Technologies
  4. Data Model Changes
  5. Migration Workflow
  6. Error Handling & Return Types
  7. API Endpoints Overview
  8. Third‑party Integrations
  9. Class Diagram (UML)
  10. Sample Code Blocks
  11. Usage Examples
  12. Conclusion

🧐 Overview & Purpose

File:
IrbyImaging.DbContext/Migrations/20240605163427_AddImagingTypes2.cs

This EF Core Migration adds two new boolean flagsβ€”IsAccounting and IsBiddingβ€”to two existing tables in the irby schema:

  • DocumentType
  • DocumentAttribute

These flags allow the application to categorize document types and attributes according to their involvement in accounting or bidding processes.


πŸš€ Key Functional Areas

  • Up(MigrationBuilder)
    • Adds non-nullable bit columns with a default of false.
    • Schema: irby, Tables: DocumentType, DocumentAttribute.
  • Down(MigrationBuilder)
    • Drops the added columns if the migration is rolled back.

πŸ›  Dependencies & Technologies

Component Version / Tech
.NET SDK β‰₯ .NET 6.0
Entity Framework Core β‰₯ 6.x
Database Provider Microsoft SQL Server (bit)
C# Language 10+

πŸ’Ύ Data Model Changes

Before Migration

Table Columns (Partial)
DocumentType Id, Name, Description
DocumentAttribute Id, Name, Value

After Migration

Table New Columns
DocumentType IsAccounting (bit, not null, default: false)IsBidding (bit, not null, default: false)
DocumentAttribute IsAccounting (bit, not null, default: false)IsBidding (bit, not null, default: false)

βš™οΈ Migration Workflow

  1. Add Migration
    dotnet ef migrations add AddImagingTypes2 --project IrbyImaging.DbContext
    
  2. Apply Migration
    dotnet ef database update --project IrbyImaging.DbContext
    
  3. Rollback (if needed)
    dotnet ef database update LastGoodMigration
    

πŸ›‘ Error Handling & Return Types

  • Both Up and Down methods return void and rely on EF Core to throw exceptions (e.g., SqlException) if the DDL operation fails.
  • Typical failure modes:
    • Column already exists / does not exist.
    • Schema/table not found.
    • Insufficient DB permissions.

🌐 API Endpoints Overview

This migration file does not define any API endpoints.
However, the new flags can be surfaced in your Web API Controllers or GraphQL resolvers, for example:

// Example: Filtering document types in a controller
[HttpGet("api/document-types/accounting")]
public async Task<IActionResult> GetAccountingDocumentTypes()
{
    var types = await _context.DocumentTypes
                              .Where(dt => dt.IsAccounting)
                              .ToListAsync();
    return Ok(types);
}

πŸ”Œ Third‑party Integrations

  • Entity Framework Core Migrations: Manages schema evolution.
  • Microsoft SQL Server: Uses the bit type for boolean flags.

πŸ“Š Class Diagram (UML)

classDiagram
    class Migration {
        <<abstract>>
        +void Up(MigrationBuilder)
        +void Down(MigrationBuilder)
    }

    class AddImagingTypes2 {
        +override void Up(MigrationBuilder)
        +override void Down(MigrationBuilder)
    }

    AddImagingTypes2 --|> Migration

    class DocumentType {
        +int Id
        +string Name
        +string Description
        +bool IsAccounting
        +bool IsBidding
    }
    class DocumentAttribute {
        +int Id
        +string Name
        +string Value
        +bool IsAccounting
        +bool IsBidding
    }

πŸ”— Legend
– <<abstract>>: Abstract base class
– --|>: Inheritance
– +: Public member


πŸ’» Sample Code Blocks

Migration Class

using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace IrbyImaging.DbContext.Migrations
{
    public partial class AddImagingTypes2 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            // Add flags to DocumentType
            migrationBuilder.AddColumn<bool>(
                name: "IsAccounting",
                schema: "irby",
                table: "DocumentType",
                type: "bit",
                nullable: false,
                defaultValue: false);

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

            // Add flags to DocumentAttribute
            migrationBuilder.AddColumn<bool>(
                name: "IsAccounting",
                schema: "irby",
                table: "DocumentAttribute",
                type: "bit",
                nullable: false,
                defaultValue: false);

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

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropColumn(name: "IsAccounting", schema: "irby", table: "DocumentType");
            migrationBuilder.DropColumn(name: "IsBidding",   schema: "irby", table: "DocumentType");
            migrationBuilder.DropColumn(name: "IsAccounting", schema: "irby", table: "DocumentAttribute");
            migrationBuilder.DropColumn(name: "IsBidding",   schema: "irby", table: "DocumentAttribute");
        }
    }
}

πŸ“š Usage Examples

  1. Querying by New Flags
    // Get all bidding-related document attributes
    var biddingAttributes = await context.DocumentAttributes
                                         .Where(attr => attr.IsBidding)
                                         .ToListAsync();
    
  2. Updating Flags at Runtime
    var docType = await context.DocumentTypes.FindAsync(typeId);
    docType.IsAccounting = true;
    await context.SaveChangesAsync();
    

🏁 Conclusion

The AddImagingTypes2 migration enriches your database schema by introducing two flagsβ€”IsAccounting and IsBiddingβ€”to both DocumentType and DocumentAttribute. These boolean indicators enable the application to easily filter, organize, and process imaging documents based on their business context (accounting vs. bidding). By following the standard EF Core migration workflow, you can seamlessly apply these changes and start leveraging the new flags across your services and APIs.

πŸ” Next Steps:

  • Update your services/controllers to make use of the new flags.
  • Add appropriate indexes if you expect heavy filtering on these columns.
  • Write integration tests to ensure correct behavior when flags change.

Happy Coding! πŸš€βœ¨