π EquipmentClass.cs Documentation
File:
IrbyImaging.DomainClasses/EquipmentClass.cs
Namespace:IrbyImaging.DomainClasses
Table:irby.EquipmentClass
π Table of Contents
- π― Overview & Purpose
- π§© Dependencies & Technologies
- ποΈ Domain Model: EquipmentClass
- π·οΈ Properties Explained
- π Entity Framework Mappings
- π οΈ Usage Examples & Code Snippets
- π UML Class Diagram
- π Integration & Relationships
- π Conclusion
π― Overview & Purpose
The EquipmentClass class is a plain old CLR object (POCO) that represents the EquipmentClass table in the irby schema of the database. It is part of the domain layer in IrbyImaging, used to:
- Model categories or classes of equipment in the imaging system.
- Provide a strongly-typed representation for CRUD operations via Entity Framework Core.
- Ensure schema-based mapping through Data Annotations.
This class has no methods or business logic β it is strictly a data container.
π§© Dependencies & Technologies
| Aspect | Details |
|---|---|
| Language | C# (.NET Standard / .NET Core) |
| ORM | Entity Framework Core (via Data Annotations) |
| Namespace | IrbyImaging.DomainClasses |
| Schema/Table Mapping | [Table("EquipmentClass", Schema = "irby")] |
| Primary Key Attribute | [Key] |
| Data Annotations | From System.ComponentModel.DataAnnotations |
| Database | Any provider supported by EF Core (e.g., SQL Server) |
ποΈ Domain Model: EquipmentClass
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace IrbyImaging.DomainClasses
{
[Table("EquipmentClass", Schema = "irby")]
public class EquipmentClass
{
[Key]
public Guid EquipmentClassId { get; set; }
public int ClassId { get; set; }
public string Name { get; set; }
}
}
Key Characteristics:
- POCO class with no business methods.
- Designed for use in a
DbContext. - Three simple properties mapping directly to database columns.
π·οΈ Properties Explained
| Property | Type | Description |
|---|---|---|
| EquipmentClassId | Guid |
Primary Key. Uniquely identifies each record. |
| ClassId | int |
Numeric identifier for the equipment class. |
| Name | string |
Human-readable name (e.g., βX-Rayβ, βMRIβ). |
- EquipmentClassId
- Decorated with
[Key], this GUID ensures global uniqueness.
- Decorated with
- ClassId
- Business-level integer ID (could correspond to legacy systems).
- Name
- Simple descriptive text; no length restriction by default.
π Entity Framework Mappings
This class uses Data Annotations to map to the database:
[Table("EquipmentClass", Schema = "irby")]
public class EquipmentClass
{
[Key]
public Guid EquipmentClassId { get; set; }
// ...
}
- Schema: irby
- Table: EquipmentClass
- Primary key: EquipmentClassId
Integration in DbContext:
public class ImagingContext : DbContext
{
public DbSet<EquipmentClass> EquipmentClasses { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseSqlServer("YourConnectionStringHere");
}
π οΈ Usage Examples & Code Snippets
1. Adding a New Equipment Class
using(var context = new ImagingContext())
{
var newClass = new EquipmentClass
{
EquipmentClassId = Guid.NewGuid(),
ClassId = 101,
Name = "Ultrasound"
};
context.EquipmentClasses.Add(newClass);
context.SaveChanges();
}
2. Querying Equipment Classes
using(var context = new ImagingContext())
{
// Fetch all classes
var allClasses = context.EquipmentClasses.ToList();
// Find by ClassId
var xrayClass = context.EquipmentClasses
.FirstOrDefault(ec => ec.ClassId == 1);
}
3. Updating a Record
using(var context = new ImagingContext())
{
var eqClass = context.EquipmentClasses.Find(existingGuid);
if (eqClass != null)
{
eqClass.Name = "Updated Name";
context.SaveChanges();
}
}
4. Deleting a Record
using(var context = new ImagingContext())
{
var toDelete = context.EquipmentClasses.Find(existingGuid);
if (toDelete != null)
{
context.EquipmentClasses.Remove(toDelete);
context.SaveChanges();
}
}
π UML Class Diagram
classDiagram
class EquipmentClass {
<<Entity>>
+Guid EquipmentClassId
+int ClassId
+string Name
}
- Entity stereotype indicates a persistent domain object.
π Integration & Relationships
- Standalone Entity: No direct navigation properties in this class.
- Potential Relationships:
- Could link to an
Equipmententity viaEquipmentClassId. - Might join with lookup tables for advanced classification.
- Could link to an
Tip: Extend this class by adding
[InverseProperty]or navigation collections in other entities.
π Conclusion
The EquipmentClass POCO is a foundational building block of the IrbyImaging domain. It:
- Provides a clean, annotation-based mapping to the database.
- Simplifies CRUD operations through EF Core.
- Is designed for easy extension when relationships or business logic arise.
By following this pattern, you maintain separation of concerns:
- DomainClasses for data structures.
- DbContext for persistence.
- Services/Repositories for business rules.
π Happy coding! If you have any questions or need further extensionβsuch as composite keys, advanced configurations, or soft deletesβfeel free to expand upon this template.