Not every entity needs the same features. A simple lookup table doesn’t need soft delete. A user’s private document needs ownership enforcement. Hazina gives you four entity base classes to match your needs.
The Four Base Classes
| Base Class | Features | Use Case |
|---|---|---|
EntityBase |
ID, CreatedAt, UpdatedAt | Simple entities, lookup tables |
SoftDeleteEntityBase |
+ IsDeleted, DeletedAt | Entities that should never truly disappear |
TenantEntityBase |
+ TenantId, automatic filtering | Multi-tenant SaaS applications |
OwnedEntityBase |
+ OwnerId, access control | User-owned content |
EntityBase – The Foundation
public class Category : EntityBase
{
public string Name { get; set; } = string.Empty;
}
// Gives you: Id, CreatedAt, UpdatedAt
SoftDeleteEntityBase – Nothing Is Ever Gone
public class Invoice : SoftDeleteEntityBase
{
public string Number { get; set; } = string.Empty;
public decimal Amount { get; set; }
}
// DELETE /api/invoices/42 sets IsDeleted=true, DeletedAt=now
// GET /api/invoices automatically excludes deleted records
// GET /api/invoices?includeDeleted=true shows everything
TenantEntityBase – Automatic Data Isolation
public class Project : TenantEntityBase
{
public string Name { get; set; } = string.Empty;
}
// Every query is automatically filtered by TenantId
// Tenant A never sees Tenant B's data
// No manual WHERE clauses needed
OwnedEntityBase – User-Level Access Control
public class Document : OwnedEntityBase
{
public string Title { get; set; } = string.Empty;
public string Content { get; set; } = string.Empty;
}
// Only the owner can see/edit their documents
// OwnerId is set automatically from the authenticated user
Combining Features
Need soft delete AND multi-tenancy? Create your own base:
public abstract class TenantSoftDeleteEntity : TenantEntityBase
{
public bool IsDeleted { get; set; }
public DateTime? DeletedAt { get; set; }
}
The framework respects all configured behaviors automatically.
In the next post, we’ll deep dive into multi-tenancy – how Hazina handles data isolation in SaaS applications.
Frequently Asked Questions
Hazina provides four base classes: EntityBase for simple entities, SoftDeleteEntityBase for entities that can be soft deleted, TenantEntityBase for multi-tenant applications, and OwnedEntityBase for user-owned content. Each class is designed to meet specific use cases and requirements.
The SoftDeleteEntityBase allows entities to be marked as deleted without being permanently removed from the database. When an entity is deleted, the IsDeleted flag is set to true, and the DeletedAt timestamp is recorded, enabling the option to retrieve deleted records if needed.
TenantEntityBase ensures automatic data isolation by filtering queries based on the TenantId. This means that each tenant can only access their own data without needing to manually add WHERE clauses, simplifying the development of multi-tenant SaaS applications.
Yes, you can create a custom base class, such as TenantSoftDeleteEntity, that incorporates both soft delete and multi-tenancy features. This allows you to manage entities that need to be soft deleted while also maintaining data isolation across tenants.