πŸ“š EquipmentClass.cs Documentation

File: IrbyImaging.DomainClasses/EquipmentClass.cs
Namespace: IrbyImaging.DomainClasses
Table: irby.EquipmentClass


πŸ“– Table of Contents

  1. 🎯 Overview & Purpose
  2. 🧩 Dependencies & Technologies
  3. πŸ›οΈ Domain Model: EquipmentClass
  4. 🏷️ Properties Explained
  5. πŸ”— Entity Framework Mappings
  6. πŸ› οΈ Usage Examples & Code Snippets
  7. 🌐 UML Class Diagram
  8. πŸ” Integration & Relationships
  9. πŸ“ 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.
  • 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 Equipment entity via EquipmentClassId.
    • Might join with lookup tables for advanced classification.

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:

  1. DomainClasses for data structures.
  2. DbContext for persistence.
  3. 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.