add: ef core

This commit is contained in:
2025-09-03 16:31:58 -03:00
parent 3c2513a567
commit f7426e16d9
9 changed files with 287 additions and 1 deletions

View File

@@ -0,0 +1,25 @@
using Microsoft.EntityFrameworkCore;
using CampusWorkshops.Api.Models;
namespace CampusWorkshops.Api.Infrastructure.Data;
public class WorkshopsDbContext : DbContext
{
public WorkshopsDbContext(DbContextOptions<WorkshopsDbContext> options) : base(options) {}
public DbSet<Workshop> Workshops => Set<Workshop>();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Workshop>(e =>
{
e.ToTable("Workshops");
e.HasKey(w => w.Id);
e.Property(w => w.Title).IsRequired().HasMaxLength(120);
e.Property(w => w.Description).HasMaxLength(2000);
e.Property(w => w.Location).HasMaxLength(200);
e.Property(w => w.Capacity).HasDefaultValue(1);
e.HasIndex(w => w.StartAt);
});
}
}