feat: Diseño del esquema de BD y configuración de Entity Framework Core

This commit is contained in:
2025-08-14 13:12:16 -03:00
parent d9bcfd7086
commit b90baadeed
75 changed files with 6890 additions and 47 deletions

View File

@@ -0,0 +1,31 @@
// src/Elecciones.Database/EleccionesDbContext.cs
using Elecciones.Database.Entities;
using Microsoft.EntityFrameworkCore;
namespace Elecciones.Database;
public class EleccionesDbContext(DbContextOptions<EleccionesDbContext> options) : DbContext(options)
{
public DbSet<AgrupacionPolitica> AgrupacionesPoliticas { get; set; }
public DbSet<AmbitoGeografico> AmbitosGeograficos { get; set; }
public DbSet<ResultadoVoto> ResultadosVotos { get; set; }
public DbSet<EstadoRecuento> EstadosRecuentos { get; set; }
// Podríamos añadir más tablas como CategoriaElectoral o ProyeccionBanca aquí
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder); // Es buena práctica llamar a la base
// Configuraciones adicionales del modelo (índices, etc.) pueden ir aquí.
// Por ejemplo, para optimizar las búsquedas.
modelBuilder.Entity<ResultadoVoto>()
.HasIndex(r => new { r.AmbitoGeograficoId, r.AgrupacionPoliticaId })
.IsUnique();
modelBuilder.Entity<EstadoRecuento>(entity =>
{
entity.Property(e => e.MesasTotalizadasPorcentaje).HasPrecision(5, 2);
entity.Property(e => e.ParticipacionPorcentaje).HasPrecision(5, 2);
});
}
}