Overview
EasyAF enforces an opinionated database design structure that promotes consistency, maintainability, and reduces boilerplate code. By implementing a set of composable interfaces, your entities automatically gain common functionality that works seamlessly with Entity Framework Core and OData Restier.Core Concepts
The EasyAF framework uses interface composition to build database entities with common patterns. Rather than inheriting from a base class, you implement specific interfaces that add the functionality you need. This approach provides flexibility while maintaining consistency across your data model.Benefits of the Interface-Based Approach
- Composability: Mix and match interfaces to get exactly the functionality you need
- Consistency: Common patterns across all tables
- Code Generation: Automatic handling of audit fields, state management, and more
- Type Safety: Generic interfaces ensure compile-time type checking
- OData Integration: Seamless integration with OData queries and filters
Naming Conventions and Design Principles
EasyAF enforces specific naming conventions that enhance code generation, improve IntelliSense experiences, and create predictable patterns across your codebase.Primary Keys: Always “Id”
Primary key properties are always namedId, never prefixed with the table name.
- Serialization efficiency: Shorter property names reduce payload size
- Predictability:
Idis always the primary key,{TableName}Idis always a foreign key - Consistency: Universal pattern across all entities
Foreign Keys: Id
Foreign key properties follow the pattern{TableName}Id to clearly indicate relationships.
Exception: Semantic Naming for Clarity
Use more descriptive names when the relationship role needs clarification:Date Properties: Prefix with “Date”
All date/time properties should be prefixed withDate followed by the semantic meaning.
- Code generation: Tools can easily identify and process date fields
- IntelliSense grouping: All date properties appear together in autocomplete lists
- Consistency: Predictable naming across the entire codebase
- Clarity: Immediately clear what the property represents
Boolean Properties: “Is” or “Has” Prefix
Boolean properties must be prefixed withIs or Has to indicate state or possession, typically in present tense.
- Use
Isfor state:IsActive,IsVisible,IsEnabled,IsPublished - Use
Hasfor possession or capability:HasOptions,HasChildren,HasAccess - Present tense preferred:
IsActiveoverWasActive - Positive phrasing preferred:
IsVisibleoverIsHidden(when practical)
DisplayName: UI-Focused Property
TheDisplayName property (from IHumanReadable) is always the primary user-facing text representation of an entity.
DisplayNameis what appears in dropdowns, lists, and labels- Other “name” properties can exist for specific purposes (
LegalName,CompanyName, etc.) - If showing users a single text value, use
DisplayName
Database Enums and SortOrder
TheSortOrder property in IDbEnum serves a dual purpose: UI ordering and C# enum mapping.
- Avoids complex EF Core enum mapping configuration
- Maintains type safety in business logic via C# enums
- Provides flexibility to change display text without code changes
- Works reliably with OData (which has inconsistent enum support)
Entity Identification
IIdentifiable<T>
The foundation of every entity in EasyAF. This interface ensures your entity has a unique identifier.EasyAF recommends using
Guid as the identifier type for most entities to avoid identity conflicts in distributed systems and simplify data synchronization.Audit Tracking
Track when entities are created and updated, and by whom.ICreatedAuditable
Tracks when an entity was created.IUpdatedAuditable
Tracks when an entity was last updated.DateUpdated is nullable because it’s only set after the first update, not on creation.ICreatorTrackable<T>
Tracks which user created the entity.IUpdaterTrackable<T>
Tracks which user last updated the entity.Active/Inactive Tracking
IActiveTrackable
Implements soft delete functionality by tracking whether an entity is active or inactive.User-Friendly Display
IHumanReadable
Provides a consistent property for displaying entity names to users.Ordering and Sorting
ISortable
Enables manual ordering of entities in lists and dropdowns.Database-Driven Enumerations
Traditional enums in code can cause problems when business logic changes. EasyAF provides a pattern for database-driven enumerations that can be updated without code changes.IDbEnum
The base interface for all database enumerations.IDbEnum combines multiple interfaces, giving you identity, active tracking, human-readable display, and sorting in one declaration.IDbStatusEnum
Specialized enumeration for tracking entity status.IDbStateEnum
Advanced enumeration for state machine workflows, providing navigation between states.Linking Entities to Enumerations
IHasStatus<T>
Links an entity to a status enumeration.IHasState<T>
Links an entity to a state enumeration for workflow management.Complete Entity Example
Here’s a comprehensive example combining multiple interfaces:Best Practices
1. Start with the Basics
Always implementIIdentifiable<Guid> as your foundation:
2. Add Audit Tracking for Business Entities
For entities that track business operations, implement full audit tracking:3. Use Soft Deletes
PreferIActiveTrackable over hard deletes:
4. Leverage Database Enumerations
Replace code enums with database enumerations for flexibility:5. Consistent Interface Ordering
Use a consistent order when implementing multiple interfaces for better readability:IIdentifiable<T>- Audit interfaces (
ICreatedAuditable, etc.) IActiveTrackableIHumanReadableISortable- Status/State interfaces
- Custom interfaces
Integration with Entity Framework Core
Configure your DbContext to respect these interfaces:Summary
EasyAF’s interface-based table design provides:- Consistency: Common patterns across all entities
- Flexibility: Compose interfaces to match your needs
- Maintainability: Centralized definitions reduce duplication
- Integration: Seamless OData and EF Core support
- Scalability: Database-driven enumerations adapt to changing business requirements