Overview
TheMunicipio (Municipality) entity represents a geographical location in the tournament management system. Each municipality can host multiple teams, establishing the geographical organization of the tournament.
Properties
Unique identifier for the municipality.
Name of the municipality.Validation Rules:
- Required field (cannot be empty)
- Must contain only letters and spaces
- Cannot start or end with whitespace
- Minimum length: 3 characters
- Maximum length: 50 characters
- Regex pattern:
^(?!^\s)(?!.*\s$)[a-zA-ZÀ-ÿ\s]+$
- Pattern mismatch: “Solo se permiten letras”
- Required: “El nombre del municipio es obligatorio.”
- Max length: “El nombre del municipio no puede tener más de 50 caracteres.”
- Min length: “El nombre del municipio no puede tener menos de 3 caracteres.”
Collection of teams based in this municipality.Default Value: Empty listRelationship: One-to-Many (One municipality can have zero or multiple teams, but each team belongs to exactly one municipality)Related Entity: Equipo
Relationships
Teams (Equipos)
A municipality can host multiple teams. This is a one-to-many relationship where the municipality is the parent entity.Navigation Property:
EquiposCardinality: One municipality to many teams (0..*)Related Entity: EquipoBusiness Rule: A municipality can have zero or multiple teams, but each team must belong to exactly one municipality.The relationship comment in the source code explicitly states: “Un municipio puede tener 0 o varios equipos, pero un equipo pertenece a un único municipio” (A municipality can have 0 or multiple teams, but a team belongs to a single municipality).
Validation Attributes
TheMunicipio entity uses the following Data Annotations:
[Required]- Ensures the municipality name is mandatory[RegularExpression]- Validates name contains only letters and spaces with no leading/trailing whitespace[MaxLength]/[MinLength]- Enforces character length constraints[Display]- Provides user-friendly display name[DisplayFormat]- Prevents empty strings from being converted to null
Code Examples
Entity Definition
Creating a Municipality
Creating a Municipality with Teams
Valid Name Examples
Invalid Name Examples
Querying Municipalities
Adding Teams to a Municipality
Municipality Statistics
Validation in Practice
Common Use Cases
Geographic Tournament Organization
Regional Leagues
Tournament Coverage
Database Mapping
The
Municipio entity is mapped to a database table with the same name. The Id property serves as the primary key and is auto-generated.The relationship with Equipo is established through a foreign key in the Equipo table pointing to the Municipio’s Id.Business Rules
Zero-to-Many Relationship
The municipality-team relationship supports the following scenarios:- New Municipality: A municipality can be created without any teams
- Active Municipality: A municipality with one or more teams
- Empty Municipality: A municipality that had teams but currently has none (teams moved or dissolved)
Data Integrity
Related Entities
- Equipo - Teams based in this municipality
- DirectorTecnico - Technical directors of teams (indirect)
- Jugador - Players on teams in this municipality (indirect)
- Partido - Matches involving teams from this municipality (indirect)