📦 PurchaseOrder Domain Class Documentation
📋 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Namespace & File Location
- Class Diagram (UML)
- Key Functional Areas
5.1. Data Model & Properties
5.2. Relationships - Attribute Annotations
- Sample Code Blocks & Usage Examples
- Integration with Entity Framework Core
- Best Practices & Notes
- 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
Jobclass 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
EachPurchaseOrderis linked to a singleJobviaJobId. - Cascade Behavior
Configure cascade delete or restrict in yourDbContext.OnModelCreatingif needed.
🏷️ Attribute Annotations
-
[Table("PurchaseOrder", Schema = "irby")]
Maps the class to tableirby.PurchaseOrder. -
[Key]
MarksPurchaseOrderIdas the primary key. -
[DataType(DataType.Date)]
Instructs UI frameworks / scaffolding to treatOrderDateas a date-only field. -
[ForeignKey("JobId")]
Denotes the navigation propertyJobis linked by theJobIdcolumn.
💻 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
-
Migrations
Add-Migration AddPurchaseOrderUpdate-Database
-
Fluent API (Optional)
- Customize relationships, table names, cascade rules in
OnModelCreating.
- Customize relationships, table names, cascade rules in
-
Seeding
- Seed initial
PurchaseOrdertemplates inDbContextif desired.
- Seed initial
📌 Best Practices & Notes
- Nullability
OrderDateis nullable (DateTime?) to represent TBD dates.
- Validation
- Additional data‑annotation attributes (e.g.,
[StringLength(100)]) can enforce field length.
- Additional data‑annotation attributes (e.g.,
- Indexing
- Consider adding indexes on
OrderDate,VendorNumberfor performance.
- Consider adding indexes on
- Concurrency
- Implement a row‑version column (
byte[] RowVersion) if concurrent edits must be managed.
- Implement a row‑version column (
🏁 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! 🛒✨