Overview
ThePartido (Match) entity represents a football match between two teams in the tournament management system. Each match has a date/time, a home team (local), a visiting team (visitante), and scores for both teams.
Properties
Unique identifier for the match.
Date and time when the match is scheduled or was played.Validation Rules:
- Required field (cannot be empty)
- Must be a valid DateTime value
- Required: “La fecha del partido es obligatoria.”
The home team playing in the match.Nullable: YesRelationship: Many-to-One (Many matches can have the same home team)Related Entity: EquipoNote: This property is referenced by the
[InverseProperty("Local")] attribute in the Equipo entity’s PartidosLocal collection.Score (goals) for the home team.Validation Rules:
- Required field
- Minimum value: 0
- Maximum value: 100
- Required: “El Marcador Local es obligatorio.”
- Range: “Marcador Local debe estar en un rango entre 0 y 100”
The visiting (away) team playing in the match.Nullable: YesRelationship: Many-to-One (Many matches can have the same visiting team)Related Entity: EquipoNote: This property is referenced by the
[InverseProperty("Visitante")] attribute in the Equipo entity’s PartidosVisitante collection.Score (goals) for the visiting team.Validation Rules:
- Required field
- Minimum value: 0
- Maximum value: 100
- Required: “El Marcador Visitante es obligatoria.”
- Range: “Marcador Visitante debe estar en un rango entre 0 y 100”
Relationships
ThePartido entity has two critical many-to-one relationships with the Equipo entity:
Home Team (Local)
The team playing at home. Multiple matches can have the same home team.Navigation Property:
LocalInverse Property: PartidosLocal in Equipo entityRelated Entity: EquipoCardinality: Many matches to one team (as home team)Visiting Team (Visitante)
The team playing away. Multiple matches can have the same visiting team.Navigation Property:
VisitanteInverse Property: PartidosVisitante in Equipo entityRelated Entity: EquipoCardinality: Many matches to one team (as visiting team)The
Local and Visitante properties create two separate relationships with the same Equipo entity. The Equipo entity uses [InverseProperty] attributes to distinguish between these two relationships, preventing ambiguous foreign key references.Validation Attributes
ThePartido entity uses the following Data Annotations:
[Required]- Ensures date/time and both scores are mandatory[Range]- Validates that scores are between 0 and 100[Display]- Provides user-friendly display names[DisplayFormat]- Configures empty value handling
Code Examples
Entity Definition
Creating a Match
Scheduling a Future Match
Recording Match Results
Valid Score Examples
Invalid Score Examples
Querying Matches
Match Statistics
Team Performance Analysis
Head-to-Head Records
Match Schedule Management
Validation Example
Business Rules
Match Scheduling
Common business rules that may need implementation:
- A team cannot play against itself
- Teams should not have overlapping match schedules
- Matches should be scheduled within tournament dates
- Consider rest days between matches for teams
Score Recording
For unplayed matches:
- Consider initializing scores to 0 or null
- Distinguish between scheduled matches (future) and completed matches (past)
- Implement logic to prevent score changes for future matches
Home/Away Balance
Database Mapping
The
Partido entity is mapped to a database table with the same name. The Id property serves as the primary key and is auto-generated.Foreign keys are created for:Localrelationship (LocalId pointing to Equipo)Visitanterelationship (VisitanteId pointing to Equipo)
[InverseProperty] attributes in the Equipo entity to distinguish between the two foreign keys.Related Entities
- Equipo - Teams participating in the match (both home and away)
- DirectorTecnico - Technical directors of teams (indirect)
- Jugador - Players on teams in the match (indirect)
- Municipio - Municipalities of teams (indirect)
- Posicion - Player positions (indirect)