📚 IrbyDataBaseEntity.cs Documentation

Assembly: IrbyImaging.DomainClasses
Filename: IrbyImaging.DomainClasses/IrbyDataBaseEntity.cs
Author: kvamshi
Created: 01‑11‑2022
Last Modified: 01‑11‑2022


📑 Table of Contents

  1. 🌟 Overview & Purpose
  2. 📦 Dependencies & Technologies
  3. 🏗️ Key Functional Areas
  4. 🔍 Error Handling & Return Types
  5. 📈 UML Class Diagram
  6. 🔧 Usage Examples
  7. 📖 Sample Code Blocks
  8. 🎯 Conclusion

🌟 Overview & Purpose

The IrbyDataBaseEntity class is a foundational domain entity within the IrbyImaging ecosystem. It extends common functionality defined in IrbyBaseEntity by adding database‐specific metadata (e.g., soft‐delete flags, auto‐save keys, load ticks). This class is intended as a base for all database‐backed entities in your imaging application.

Key Responsibilities

  • 📋 Managing entity metadata (creation/update audit via CommonEntityProps)
  • 💤 Implementing a soft-delete pattern (IsInactive)
  • 🔑 Holding an autosave key (AutosaveEntryKey) for draft versions
  • ⏱️ Tracking load ticks (LoadedTicks) for concurrency or UI purposes

📦 Dependencies & Technologies

Technology / Namespace Purpose
System Base types (Guid, Exception, etc.)
System.Collections.Generic Collections support (imported)
System.ComponentModel DefaultValue attribute
System.ComponentModel.DataAnnotations.Schema NotMapped attribute for EF Core
System.Text.Json.Serialization JSON serialization support (imported)

Note: While System.Text.Json.Serialization is imported, this specific file does not surface JSON attributes directly. It’s ready for potential [JsonIgnore] or [JsonPropertyName] adornments.


🏗️ Key Functional Areas

Class Declaration & Inheritance

public class IrbyDataBaseEntity : IrbyBaseEntity
  • Base Class: IrbyBaseEntity
  • Purpose: Enriches base entity with database‐centric fields.
  • Namespace: IrbyImaging.DomainClasses

Constructors

  1. Default Constructor

    public IrbyDataBaseEntity()
    {
        _rowInfo = new CommonEntityProps();
    }
    
    • Initializes the private _rowInfo (inherited) to a new CommonEntityProps instance.
    • Ensures audit metadata is always available.
  2. Overloaded Constructor

    public IrbyDataBaseEntity(CommonEntityProps rowInfo)
    {
        if (rowInfo == null)
            throw new NullReferenceException("Overloaded constructor parameter, rowInfo, cannot be null");
        this._rowInfo = rowInfo;
    }
    
    • Allows dependency injection of metadata.
    • Validates against null to prevent misuse.

Properties

Property Name Type Description
bool? IsInactive bool? Soft‑delete marker. true → entity is inactive (soft‑deleted), false → active, null → not set. Defaults to false.
string LoadedTicks string Tracks the moment (ticks) when the entity was loaded. Useful for optimistic concurrency or UI‑level caching.
Guid? AutosaveEntryKey Guid? Key for draft/autosave workflows. When non‐null, points to a draft state in an autosave table or cache.

Attributes & Annotations

Attribute Target Purpose
[DefaultValue("false")] IsInactive Designates the default value for the soft‑delete flag when an entity is added to the DB.
[NotMapped] LoadedTicks Instructs Entity Framework to ignore LoadedTicks when mapping to database tables.

🔍 Error Handling & Return Types

  • NullReferenceException in overloaded constructor if rowInfo is null.
  • Nullable types (bool?, Guid?) denote optional values and avoid forcing defaults.
  • No return types aside from constructors – all properties are auto‐implemented.

📈 UML Class Diagram

classDiagram
    IrbyBaseEntity <|-- IrbyDataBaseEntity
    IrbyDataBaseEntity : +bool? IsInactive {DefaultValue=false}
    IrbyDataBaseEntity : +string LoadedTicks <<NotMapped>>
    IrbyDataBaseEntity : +Guid? AutosaveEntryKey
    IrbyDataBaseEntity : +IrbyDataBaseEntity()
    IrbyDataBaseEntity : +IrbyDataBaseEntity(CommonEntityProps rowInfo)
    IrbyDataBaseEntity --> CommonEntityProps

🔧 Usage Examples

1. Deriving a Domain Entity

public class Customer : IrbyDataBaseEntity
{
    public int CustomerId { get; set; }
    public string Name { get; set; }
    // Inherits IsInactive, LoadedTicks, AutosaveEntryKey
}

2. Soft‑Delete Pattern

var customer = dbContext.Customers.Find(id);
customer.IsInactive = true; 
dbContext.SaveChanges();
// The row remains in the table but is marked inactive.

3. Using LoadedTicks for Concurrency

var customer = dbContext.Customers.AsNoTracking().First();
customer.LoadedTicks = DateTime.UtcNow.Ticks.ToString();
// Pass LoadedTicks back to UI to detect stale data on update

4. Injecting Custom CommonEntityProps

var props = new CommonEntityProps
{
    CreatedBy = "admin",
    CreatedOn = DateTime.UtcNow
};
var invoice = new Invoice(props) { /* ... */ };
dbContext.Invoices.Add(invoice);
dbContext.SaveChanges();

📖 Sample Code Blocks

// Default instantiation
var entity = new IrbyDataBaseEntity();
Console.WriteLine(entity.IsInactive);          // false (default)
Console.WriteLine(entity.AutosaveEntryKey);    // null

// Overloaded constructor
CommonEntityProps props = GetRowInfoFromContext();
var customEntity = new IrbyDataBaseEntity(props);

🎯 Conclusion

The IrbyDataBaseEntity class centralizes common database behavior—from soft‑deletion and auditing to autosaving and concurrency aids. By inheriting from IrbyBaseEntity, it ensures that every domain object has a consistent set of properties and patterns, reducing boilerplate and enforcing best practices across the IrbyImaging application.

Feel free to extend this class for your own domain entities, tap into the provided metadata, and integrate it seamlessly with Entity Framework for robust data handling. 🚀