Overview
TechCore’s entity models are located in~/workspace/source/TechCore/Models/ and represent the database schema using Entity Framework Core conventions. All models are partial classes, allowing for extension and customization.
Model Categories
Core Business Entities
- Cliente - Customer information
- Producto - Product catalog
- Categorium - Product categories
- Proveedore - Supplier information
Transaction Entities
- Venta - Sales orders
- VentasDetalle - Sale line items
- Compra - Purchase orders
- ComprasDetalle - Purchase line items
Financial Entities
- AbonosVenta - Sale payments
- PlanPago - Payment installment plans
System Entities
- User - Application users
- Rol - User roles
View Entities
- VwCuotasPorVencer - Upcoming installments
- VwCuotasVencida - Overdue installments
- VwEstadoCuentum - Account balances
Core Entities
Cliente (Customer)
Location:~/workspace/source/TechCore/Models/Cliente.cs
- String-based primary key (
Codclien) - Soft delete with
Estadoflag - One-to-many relationship with sales
- Created date tracking
Producto (Product)
Location:~/workspace/source/TechCore/Models/Producto.cs
- String-based product code as primary key
- Purchase and sale prices
- Stock management with minimum threshold
- Belongs to a category
- Used in both sales and purchases
Categorium (Category)
Location:~/workspace/source/TechCore/Models/Categorium.cs
- Integer identity primary key
- Unique string code for business reference
- One-to-many relationship with products
Transaction Entities
Venta (Sale)
Location:~/workspace/source/TechCore/Models/Venta.cs
- Complex master entity with multiple relationships
- Supports both cash and credit sales
- Tracks installment plans with interest
- Multiple related collections:
- Sale details (line items)
- Payment plans
- Payments received
- Can be voided (
Nulaflag)
VentasDetalle (Sale Line Item)
Location:~/workspace/source/TechCore/Models/VentasDetalle.cs
TR_DisminuirStock that automatically decreases product stock when a sale detail is inserted.
Compra (Purchase Order)
Location:~/workspace/source/TechCore/Models/Compra.cs
- Master-detail structure similar to sales
- Links to supplier (
Proveedore) - Links to user who created the purchase
- Integer estado for status tracking
Financial Entities
AbonosVenta (Sale Payment)
Location:~/workspace/source/TechCore/Models/AbonosVenta.cs
Tracks individual payments made against credit sales:
TR_ActualizarSaldo that automatically updates the sale’s balance when a payment is recorded.
PlanPago (Payment Plan)
Location:~/workspace/source/TechCore/Models/PlanPago.cs
Defines the installment schedule for credit sales:
- Defines when each installment is due
- Tracks whether installment is paid
- Used by payment monitoring views
System Entities
User
Location:~/workspace/source/TechCore/Models/User.cs
- Users create both sales and purchases
- Must belong to a role
- Unique code and username
Rol (Role)
Location:~/workspace/source/TechCore/Models/Rol.cs
Navigation Property Patterns
Naming Conventions
Entity Framework Core navigation properties follow these patterns:Foreign Key Navigation (Many-to-One)
Collection Navigation (One-to-Many)
Initialization Pattern
All collection navigations are initialized to prevent null reference exceptions:Partial Class Pattern
All models use thepartial keyword:
- Code generation - EF Core scaffolding can regenerate models without losing customizations
- Extensions - Add computed properties, methods, or validation in separate files
- Data annotations - Add validation attributes in custom partial class files
Example Extension
Create a separate fileProducto.Custom.cs:
Nullable Reference Types
The project uses nullable reference types (<Nullable>enable</Nullable>):
Non-nullable (required)
= null! suppresses the compiler warning while indicating the property will be set by EF Core.
Nullable (optional)
Common Property Patterns
Audit Fields
Status Flags
Financial Fields
Order Tracking
Working with Models
Querying with Navigation Properties
Loading Related Collections
Creating Related Entities
Best Practices
- Always use navigation properties instead of manual joins
- Use Include() for eager loading to avoid N+1 queries
- Initialize collections in constructors or property initializers
- Use partial classes for adding custom logic without modifying generated code
- Respect soft deletes - filter by
Estadoflags - Handle nullable types properly with null-conditional operators
Next Steps
- Review Data Access Layer for DbContext configuration
- Explore Application Architecture for overall structure