Files
Workshop10-API/Infraestructure/Data/WorkshopDBContext.cs

26 lines
834 B
C#
Raw Normal View History

2025-09-03 16:31:58 -03:00
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);
});
}
}