Entity Model Documentation
This guide covers how to define entities, properties, relationships, and data types in Benevia Core. The entity model system uses C# partial classes with attributes that drive source generation for OData API controllers and the database schema.
Register your model in program.cs
If you created your solution with the Benevia solution template (see Quick Start), then this is already done for you.
This should be done on startup in your program.cs. The method is automatically generated and is the name of your project. In this example, Benevia.ERP.Model is the project name. See the last line in the code below:
var builder = WebApplication.CreateBuilder(args);
builder
.AddCoreOpenTelemetry()
.AddErpBlobs()
.AddCorsFromConfig();
builder.Services
.AddCorePostgres()
.AddCoreDataGeneration()
.AddCoreLargeData()
.AddCoreContacts()
.AddBeneviaERPModel();
Learning Path
Start with the basics and work through these documents in order:
| # | Document | Description |
|---|---|---|
| 1 | Entity Basics | Creating an entity class, [ApiEntity], EntityBase, natural keys, and enums |
| 2 | Properties | Defining scalar properties with [Property<T>], labels, defaults, and computed values |
| 3 | Relationships | Reference properties, collections, delete actions, and relationship types |
| 4 | Search | Full-text search with [Searchable], navigation search, and dictionary options |
| 5 | Methods | Custom entity actions with [Method], parameter classes, and read vs modify |
| 6 | Virtual Entities | Non-persisted computed entities for aggregation and read-only views |
Advanced Topics
| Document | Description |
|---|---|
| Interfaces | Shared property contracts with interface logic, interface inheritance, and placeholders |
Reference
| Document | Description |
|---|---|
| Data Types | Complete list of all built-in and ERP-specific data types |
| Creating Data Types | How to build custom data types with validation and auto-correction |
Related Documentation
- Events System — Business logic, compute, validate, and presave events
- Database Upgrades — Schema migration and property-added events