📦 PurchaseOrder Domain Class Documentation


📋 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Namespace & File Location
  4. Class Diagram (UML)
  5. Key Functional Areas
    5.1. Data Model & Properties
    5.2. Relationships
  6. Attribute Annotations
  7. Sample Code Blocks & Usage Examples
  8. Integration with Entity Framework Core
  9. Best Practices & Notes
  10. Conclusion

🔍 Overview & Purpose

The PurchaseOrder class represents a purchase order record in the Irby Imaging domain. It is a plain CLR object (POCO) decorated with Entity Framework Core data annotations to map to the underlying database table. Each instance of PurchaseOrder corresponds to one row in the irby.PurchaseOrder table.

Primary responsibilities

  • Store metadata about a purchase order (e.g., order date, vendor information).
  • Maintain a foreign‑key relationship to its associated Job.
  • Serve as the data model for CRUD operations via Entity Framework Core.

🛠 Dependencies & Technologies

Technology / Package Purpose
.NET ( ≥4.6 / .NET Core) Runtime environment
EntityFrameworkCore (Microsoft.EntityFrameworkCore) ORM for mapping .NET objects to database tables
System.ComponentModel.DataAnnotations Validation & schema attributes
System.ComponentModel.DataAnnotations.Schema Table/Column mapping

📂 Namespace & File Location

IrbyImaging.DomainClasses
└── PurchaseOrder.cs
  • Namespace: IrbyImaging.DomainClasses
  • File Path: IrbyImaging.DomainClasses/PurchaseOrder.cs

📊 Class Diagram (UML)

@startuml
namespace IrbyImaging.DomainClasses {
  class PurchaseOrder {
    + Guid PurchaseOrderId
    + string Org_Bu
    + string Org_IntDivision
    + string Name
    + string DisplayName
    + DateTime? OrderDate
    + string OrderNumber
    + string Type
    + string Description
    + string VendorName
    + string VendorNumber
    + Guid JobId
    + Job Job
  }

  class Job {
    + Guid JobId
    + string Title
    // ...other properties
  }

  PurchaseOrder "1" --> "1" Job : FK >
}
@enduml

Note: Replace the Job class stub with your actual definition.


🔑 Key Functional Areas

5.1 Data Model & Properties

Property Type Attributes Description
PurchaseOrderId Guid [Key] Primary key of the purchase order.
Org_Bu string Organizational business unit code.
Org_IntDivision string Internal division identifier.
Name string System name or internal reference of the PO.
DisplayName string User‑friendly name for display.
OrderDate DateTime? [DataType(DataType.Date)] Date when the order was placed.
OrderNumber string Vendor’s purchase order number.
Type string Categorization or type of purchase (e.g., “Standard”, “Urgent”).
Description string Free‑text description of the order.
VendorName string Name of the vendor or supplier.
VendorNumber string Vendor’s internal identifier or code.
JobId Guid [ForeignKey("JobId")] Reference key to the associated Job record.
Job Job Navigation property for the related Job.

5.2 Relationships

  • One‑to‑One / Many‑to‑One
    Each PurchaseOrder is linked to a single Job via JobId.
  • Cascade Behavior
    Configure cascade delete or restrict in your DbContext.OnModelCreating if needed.

🏷️ Attribute Annotations

  • [Table("PurchaseOrder", Schema = "irby")]
    Maps the class to table irby.PurchaseOrder.

  • [Key]
    Marks PurchaseOrderId as the primary key.

  • [DataType(DataType.Date)]
    Instructs UI frameworks / scaffolding to treat OrderDate as a date-only field.

  • [ForeignKey("JobId")]
    Denotes the navigation property Job is linked by the JobId column.


💻 Sample Code Blocks & Usage Examples

1. Creating a New PurchaseOrder

using IrbyImaging.DomainClasses;

// Instantiate
var po = new PurchaseOrder
{
    PurchaseOrderId   = Guid.NewGuid(),
    Org_Bu            = "BU123",
    Org_IntDivision   = "DIV001",
    Name              = "PO_2024_0001",
    DisplayName       = "PO January 2024",
    OrderDate         = DateTime.UtcNow.Date,
    OrderNumber       = "IRBY-PO-2024-0001",
    Type              = "Standard",
    Description       = "Imaging equipment order",
    VendorName        = "Acme Imaging Supplies",
    VendorNumber      = "VEND-9876",
    JobId             = existingJob.JobId // assume existingJob retrieved earlier
};

2. Adding to EF Core DbContext

public class IrbyDbContext : DbContext
{
    public DbSet<PurchaseOrder> PurchaseOrders { get; set; }
    public DbSet<Job> Jobs { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        // Optional: Fluent API overrides
        modelBuilder.Entity<PurchaseOrder>()
            .HasOne(po => po.Job)
            .WithMany(j => j.PurchaseOrders)  // if collection on Job
            .HasForeignKey(po => po.JobId)
            .OnDelete(DeleteBehavior.Restrict);
    }
}

// Usage
using var ctx = new IrbyDbContext();
ctx.PurchaseOrders.Add(po);
ctx.SaveChanges();

3. Querying PurchaseOrders

var recentOrders = ctx.PurchaseOrders
    .Include(po => po.Job)
    .Where(po => po.OrderDate >= DateTime.UtcNow.AddMonths(-1))
    .OrderBy(po => po.OrderDate)
    .ToList();

🔗 Integration with Entity Framework Core

  1. Migrations

    • Add-Migration AddPurchaseOrder
    • Update-Database
  2. Fluent API (Optional)

    • Customize relationships, table names, cascade rules in OnModelCreating.
  3. Seeding

    • Seed initial PurchaseOrder templates in DbContext if desired.

📌 Best Practices & Notes

  • Nullability
    • OrderDate is nullable (DateTime?) to represent TBD dates.
  • Validation
    • Additional data‑annotation attributes (e.g., [StringLength(100)]) can enforce field length.
  • Indexing
    • Consider adding indexes on OrderDate, VendorNumber for performance.
  • Concurrency
    • Implement a row‑version column (byte[] RowVersion) if concurrent edits must be managed.

🏁 Conclusion

The PurchaseOrder domain class is a straightforward, annotation‑driven C# entity designed for seamless integration with EF Core. It holds all relevant metadata for a purchase order in the Irby Imaging system and maintains a strong link to its related Job. Utilize the provided samples and best practices to CRUD, query, and manage orders effectively in your data layer. 🚀


Happy coding! 🛒✨