Naming Conventions
C# Classes and Properties
Follow standard C# naming conventions:-
Classes: Use PascalCase for class names
-
Properties: Use PascalCase for property names
-
Navigation Properties: Use descriptive names with “Navigation” suffix
Database Column Mapping
Database column names use lowercase with camelCase for compound words:Model Classes
Partial Classes
All model classes are declared aspartial to allow for extensions:
Null-Forgiving Operator
Use the null-forgiving operator (= null!) for required properties that Entity Framework will initialize:
Nullable Properties
Use nullable types (?) for optional properties:
Collection Initialization
Initialize navigation collections to empty lists:Entity Framework Configuration
DbContext Configuration
Configure Entity Framework inTechCoreContext.cs using the Fluent API in OnModelCreating:
Indexes
Define indexes for frequently queried columns:Foreign Key Relationships
Configure relationships with proper delete behavior:Default Values
Set database default values in configuration:Data Types
Decimal Precision
Use consistent decimal precision for monetary values:String Lengths
Define appropriate maximum lengths for string properties:Controllers
Controller Structure
Follow ASP.NET Core MVC conventions:Dependency Injection
Register services inProgram.cs:
File Organization
Best Practices
- Use partial classes for all models to allow extensions
- Always specify column names explicitly in Entity Framework configuration
- Use PascalCase for all C# identifiers (classes, properties, methods)
- Use lowercase/camelCase for database column names
- Initialize collections to empty lists to avoid null reference exceptions
- Use nullable types appropriately to reflect database schema
- Define indexes on foreign keys and frequently queried columns
- Set default values in Entity Framework configuration to match database defaults
- Use
virtualkeyword for navigation properties to enable lazy loading - Keep controllers thin - business logic should be in separate service classes