add: ef core
This commit is contained in:
25
Infraestructure/Data/WorkshopDBContext.cs
Normal file
25
Infraestructure/Data/WorkshopDBContext.cs
Normal 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);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user