Overview
TheIRepositorioDT interface and RepositorioDT implementation provide data access operations for managing technical directors in the tournament system. Each technical director can be associated with multiple teams.
Interface Definition
IRepositorioDT.cs
Implementation
RepositorioDT.cs
Methods Reference
AddDT
Adds a new technical director to the database.DirectorTecnico
required
The DirectorTecnico entity to add
DirectorTecnico
The inserted DirectorTecnico entity with its generated ID
Implementation (Lines 8-14)
GetAllDTs
Retrieves all technical directors with their associated teams.IEnumerable<DirectorTecnico>
Collection of all DirectorTecnico entities with eagerly loaded Equipos
Implementation (Lines 16-28)
- Uses
.Include(e => e.Equipos)to eagerly load related teams - Uses
.AsNoTracking()for improved read performance - Returns complete object graph including teams
GetDT
Retrieves a specific technical director by ID.int
required
The ID of the technical director to retrieve
DirectorTecnico
The DirectorTecnico entity, or null if not found
Implementation (Lines 29-33)
UpdateDT
Updates an existing technical director’s information.DirectorTecnico
required
The DirectorTecnico entity with updated values (must include valid Id)
DirectorTecnico
The updated DirectorTecnico entity
Exception
Throws exception with message “DT not found” if the ID doesn’t exist
Implementation (Lines 34-49)
Nombre- Technical director’s nameDocumento- Identification document numberTelefono- Phone number
DeleteDT
Deletes a technical director from the database.int
required
The ID of the technical director to delete
DirectorTecnico
The deleted DirectorTecnico entity
Exception
Throws exception with message “DT not found” if the ID doesn’t exist
Implementation (Lines 50-63)
Deleting a technical director may fail if they are referenced by teams due to foreign key constraints configured with
DeleteBehavior.Restrict.validateDuplicates
Validates whether a technical director’s document number already exists in the database.DirectorTecnico
required
The DirectorTecnico entity to validate
bool
true if a duplicate document exists (different DT with same document), false otherwiseImplementation (Lines 65-102)
- Compares
Documentofield (trimmed) with existing records - If same ID, allows update (not considered duplicate)
- If different ID with same document, marks as duplicate
- Returns
falseon any exception
Dependency Injection
Register the repository inProgram.cs:
Related Entities
DirectorTecnico Entity
Domain model for technical directors
Equipo Repository
Teams managed by technical directors
Common Workflows
Creating a Technical Director
Creating a Technical Director
Updating a Technical Director
Updating a Technical Director
Listing All Technical Directors with Teams
Listing All Technical Directors with Teams
Error Handling
Performance Considerations
GetAllDTs()uses.AsNoTracking()for improved read performancevalidateDuplicates()callsGetAllDTs(), which may be inefficient for large datasets- Consider implementing indexed queries for duplicate validation in production