Overview
This module creates:- Domain entity classes
- Entity interfaces (optional)
- Domain enums
- Collection wrappers
- Update helper methods
- Exception classes (NotFoundException)
Installation
Key Features
Entity Generation
Entities are generated from your domain model with:- Properties with appropriate types and nullability
- Constructors with parameters
- Navigation properties for relationships
- Methods for business logic
- Support for inheritance
- Generic type parameters
Example Entity
Entity Interfaces
When Create Entity Interfaces is enabled, interfaces are generated:Entity Interface
Domain Enums
Domain Enum
Value Objects
Supports value object generation:Value Object
Configuration Options
Separate State from Behaviour
Separate State from Behaviour
Generates separate partial classes for entity state and behavior.When enabled:
CustomerState.cs- Contains propertiesCustomer.cs- Contains methods and constructors
- Cleaner code organization
- Better separation of concerns
- Easier code generation management
falseCreate Entity Interfaces
Create Entity Interfaces
Generates interfaces for all domain entities.Benefits:
- Improved testability
- Better abstraction
- Support for dependency injection
falseEnsure Private Property Setters
Ensure Private Property Setters
Makes all property setters private, enforcing encapsulation.Example:Benefits:
- Enforces invariants
- Prevents external modification
- Encourages method-based updates
trueUse Implicit Tag Mode for Entities
Use Implicit Tag Mode for Entities
Uses implicit Intent tag mode for entity files.Reduces the need for explicit
[IntentManaged] attributes.Default: trueEntity Relationships
One-to-Many
One-to-Many
Many-to-Many
Many-to-Many
One-to-One
One-to-One
Inheritance
Supports entity inheritance:Inheritance
Constructors
Multiple constructor patterns:Parameterized Constructor
Parameterized
Protected Parameterless Constructor
Protected Constructor
- EF Core materialization
- Serialization
- Testing frameworks
Methods
Update Methods
Update Methods
Business Logic
Business Logic
Exceptions
The module generates aNotFoundException for missing entities:
NotFoundException
Usage
Collection Helpers
Generated collection extension methods:Collection Extensions
Code-to-Model Synchronization
The module supports synchronizing code changes back to the domain model:- Add methods in code → Appear in domain model
- Rename properties → Updates domain model
- Add attributes → Creates in domain model
- Delete elements → Removes from domain model
Enable Code-to-Model synchronization in the domain designer settings.
Best Practices
Encapsulation
Use private setters and public methods to enforce business rules and invariants.
Rich Domain Model
Add business logic methods directly to entities rather than in services.
Immutability
Consider making value objects immutable for better predictability.
Constructor Validation
Validate parameters in constructors to ensure entities are always in valid states.
Related Modules
- Entity Framework Core - Persistence
- Domain Events - Domain event handling
- Domain Services - Domain service generation
- EF Core Repositories - Repository access
