Overview
TheIRepositorioEquipo interface and RepositorioEquipo implementation provide comprehensive data access operations for managing teams. This repository includes advanced features like search by name, filtering by municipality, and managing relationships with municipalities and technical directors.
Interface Definition
IRepositorioEquipo.cs
Implementation
RepositorioEquipo.cs
Methods Reference
AddEquipo
Adds a new team to the database with associations to municipality and technical director.Equipo
required
The Equipo entity to add
int
required
The ID of the municipality where the team is based
int
required
The ID of the technical director managing the team
Equipo
The inserted Equipo entity with its generated ID and populated relationships
Implementation (Lines 10-19)
- Validates municipality and technical director exist before association
- Sets relationships to
nullif referenced entities don’t exist - Returns complete entity with relationships
GetAllEquipos
Retrieves all teams with complete relationship graph.IEnumerable<Equipo>
Collection of all Equipo entities with eagerly loaded relationships
Implementation (Lines 20-35)
Municipio- The team’s home municipalityDirectorTecnico- The team’s technical directorJugadores- All players on the teamPartidosLocal- Matches where team plays as home teamPartidosVisitante- Matches where team plays as visiting team
GetEquipo
Retrieves a specific team by ID with municipality and technical director relationships.int
required
The ID of the team to retrieve
Equipo
The Equipo entity with Municipio and DirectorTecnico loaded, or null if not found
Implementation (Lines 37-45)
UpdateEquipo
Updates an existing team’s information and relationships.Equipo
required
The Equipo entity with updated values (must include valid Id)
int
required
The ID of the new municipality (or existing)
int
required
The ID of the new technical director (or existing)
Equipo
The updated Equipo entity with current relationships
Implementation (Lines 47-57)
Nombre- Team nameMunicipio- Associated municipalityDirectorTecnico- Associated technical director
DeleteEquipo
Deletes a team from the database.int
required
The ID of the team to delete
Equipo
The deleted Equipo entity, or null if not found
Implementation (Lines 59-76)
GetEquiposMunicipio
Retrieves all teams belonging to a specific municipality.int
required
The ID of the municipality
IEnumerable<Equipo>
Collection of Equipo entities from the specified municipality with full relationships
Implementation (Lines 78-91)
SearchEquipos
Searches for teams by name using partial matching.string
required
The search term to match against team names (case-sensitive partial match)
IEnumerable<Equipo>
Collection of Equipo entities whose names contain the search term
Implementation (Lines 92-102)
- Uses
.Contains()for partial string matching - Loads complete relationship graph
- Case-sensitive search
validateDuplicates
Validates whether a team name already exists in the database.Equipo
required
The Equipo entity to validate
bool
true if a team with the same name already exists, false otherwiseImplementation (Lines 145-170)
- Case-insensitive comparison using
.ToLower() - Trims whitespace from input
- Returns
falseon any exception
This validation does NOT exclude the current entity when updating (unlike DirectorTecnico validation). Any team with a matching name will be flagged as duplicate.
Dependency Injection
Register the repository inProgram.cs:
Program.cs (Line 18)
Common Workflows
Creating a Team with Relationships
Creating a Team with Relationships
Searching and Filtering Teams
Searching and Filtering Teams
Updating Team Relationships
Updating Team Relationships
Getting Team Statistics
Getting Team Statistics
Related Entities
Equipo Entity
Domain model for teams
Municipio Repository
Municipality data access
DirectorTecnico Repository
Technical director data access
Jugador Repository
Player data access
Partido Repository
Match data access
Performance Considerations
Optimization Tips:
GetAllEquipos()loads complete relationship graph - useGetEquipo()for single entitiesSearchEquipos()performs case-sensitive search - consider adding case-insensitive variantvalidateDuplicates()loads all teams - consider indexed query for production- All read operations use
.AsNoTracking()for better performance