πŸ“„ IrbyBaseEntity.cs Documentation


πŸ“‘ Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Class Definition & UML Diagram
  4. Key Functional Areas
  5. Constructors & Initialization
  6. Properties
  7. Helper Methods & Utilities
  8. Error Handling & Exceptions
  9. API Endpoints Overview
  10. Third-party Integrations
  11. Sample Code & Usage Examples
  12. Conclusion

1. Overview & Purpose

IrbyBaseEntity serves as a foundation for all domain entities in the IrbyImaging.DomainClasses assembly. It encapsulates:

  • πŸ“‹ Common audit properties (via CommonEntityProps)
  • 🚩 A soft-delete marker
  • πŸ”„ Shared constructor logic

Reusing IrbyBaseEntity ensures consistency in how entities track creation/update metadata and deletion state across the entire domain model.


2. Dependencies & Technologies

Dependency Purpose
System Base .NET types (e.g., NullReferenceException)
System.ComponentModel.DataAnnotations.Schema EF Core attribute [NotMapped]
IrbyImaging.DomainClasses.CommonEntityProps Audit & row-related properties
  • .NET Standard/Core compatibility
  • Designed for Entity Framework (EF Core) or similar ORMs

3. Class Definition & UML Diagram

namespace IrbyImaging.DomainClasses
{
    public class IrbyBaseEntity
    {
        protected CommonEntityProps _rowInfo;
        public virtual CommonEntityProps RowInfo { get; set; }

        [NotMapped]
        public bool? Deleted { get; set; }

        public IrbyBaseEntity();
        public IrbyBaseEntity(CommonEntityProps rowInfo);
    }
}

UML Class Diagram (Mermaid)

classDiagram
    class IrbyBaseEntity {
        -CommonEntityProps _rowInfo
        +CommonEntityProps RowInfo {get; set;}
        +bool? Deleted {get; set;}
        +IrbyBaseEntity()
        +IrbyBaseEntity(CommonEntityProps rowInfo)
    }

    class CommonEntityProps {
        <<external>>
        // e.g. DateTime CreatedDate, string CreatedBy, DateTime? UpdatedDate, string UpdatedBy
    }

    IrbyBaseEntity --> CommonEntityProps : has-a

4. Key Functional Areas

  1. Audit Metadata
    • Houses creation, modification, and user-tracking fields through RowInfo.
  2. Soft-Delete Mechanism
    • The Deleted flag allows marking an entity as deleted without physically removing it from the database.
  3. Base Constructors
    • Ensures _rowInfo is never null at runtime.

5. Constructors & Initialization

Constructor Signature Behavior
public IrbyBaseEntity() Instantiates _rowInfo to a new CommonEntityProps object.
public IrbyBaseEntity(CommonEntityProps rowInfo) Uses provided rowInfo; throws if null.
/// Default ctor: always ensures a non-null RowInfo
public IrbyBaseEntity()
{
    _rowInfo = new CommonEntityProps();
}

/// Overloaded ctor: accept existing rowInfo or throw NullReferenceException
public IrbyBaseEntity(CommonEntityProps rowInfo)
{
    if (rowInfo == null)
        throw new NullReferenceException("Overloaded constructor parameter, rowInfo, cannot be null");
    this._rowInfo = rowInfo;
}

6. Properties

Property Type Description Attributes
RowInfo CommonEntityProps Audit metadata (CreatedBy, CreatedDate, etc.). β€”
Deleted bool? Soft-delete indicator (true = deleted). [NotMapped]

Notes:

  • RowInfo is marked virtual to allow EF lazy-loading or proxying if needed.
  • Deleted decorated with [NotMapped] to prevent persisting this temporary flag in the databaseβ€”it’s meant for in-memory logic only.

7. Helper Methods & Utilities

Currently, IrbyBaseEntity does not include custom helper methods. It relies on:

  • CommonEntityProps for audit tracking
  • EF Core for mapping and proxying

You may extend this base by:

public class MyEntity : IrbyBaseEntity
{
    public int Id { get; set; }
    public string Name { get; set; }

    // Additional domain logic...
}

8. Error Handling & Exceptions

  • NullReferenceException
    • Thrown in the overloaded constructor when rowInfo parameter is null.
    • Encourages consumers to always provide a valid CommonEntityProps or use the parameterless ctor.

9. API Endpoints Overview

🚫 No direct API endpoints are defined in this file.
It is purely a domain/data model class to be consumed by services or controllers elsewhere.


10. Third-party Integrations

  • Entity Framework Core
    • The [NotMapped] attribute originates from System.ComponentModel.DataAnnotations.Schema.

No other third-party libraries are referenced directly.


11. Sample Code & Usage Examples

11.1. Basic Inheritance

public class Patient : IrbyBaseEntity
{
    public int PatientId { get; set; }
    public string FullName { get; set; }
}

// Usage
var patient = new Patient();
patient.RowInfo.CreatedBy = "jdoe";
patient.RowInfo.CreatedDate = DateTime.UtcNow;
patient.FullName = "John Doe";

11.2. Soft-Delete Pattern

public void RemovePatient(Patient patient)
{
    // Instead of deleting from DB:
    patient.Deleted = true;
    // SaveChanges on your DbContext will ignore [NotMapped] β†’ you must manually handle soft-delete logic.
}

11.3. Providing Custom RowInfo

var customProps = new CommonEntityProps
{
    CreatedBy = "admin",
    CreatedDate = DateTime.UtcNow
};

var entity = new Patient(customProps);

12. Conclusion

IrbyBaseEntity is a lightweight, reusable base class designed to standardize:

  • πŸ“‹ Audit metadata via CommonEntityProps
  • 🚩 Soft-delete support with an in-memory flag
  • πŸ”„ Safe initialization through thoughtful constructors

Use this base to kickstart your domain entities, maintain consistent auditing, and implement soft-delete patterns across your application.

✨ Happy coding!