π IrbyBaseEntity.cs Documentation
π Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Class Definition & UML Diagram
- Key Functional Areas
- Constructors & Initialization
- Properties
- Helper Methods & Utilities
- Error Handling & Exceptions
- API Endpoints Overview
- Third-party Integrations
- Sample Code & Usage Examples
- 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
- Audit Metadata
- Houses creation, modification, and user-tracking fields through
RowInfo.
- Houses creation, modification, and user-tracking fields through
- Soft-Delete Mechanism
- The
Deletedflag allows marking an entity as deleted without physically removing it from the database.
- The
- Base Constructors
- Ensures
_rowInfois never null at runtime.
- Ensures
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:
RowInfois markedvirtualto allow EF lazy-loading or proxying if needed.Deleteddecorated 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
rowInfoparameter isnull. - Encourages consumers to always provide a valid
CommonEntityPropsor use the parameterless ctor.
- Thrown in the overloaded constructor when
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 fromSystem.ComponentModel.DataAnnotations.Schema.
- The
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!