Add EventOccurrence entity and update DbContext

Created the EventOccurrence entity with properties for event details and added it to the AppDbContext. Updated the model snapshot to reflect the new entity and its relationships, ensuring proper database schema generation.
This commit is contained in:
2025-12-27 15:59:48 -05:00
parent eaefdfaedd
commit 3a809f18a6
6 changed files with 522 additions and 3 deletions
@@ -0,0 +1,48 @@
using Core.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Data.Configurations
{
public class EventOccurrenceConfiguration : IEntityTypeConfiguration<EventOccurrence>
{
public void Configure(EntityTypeBuilder<EventOccurrence> builder)
{
builder.HasKey(e => e.Id);
// Indexes
builder.HasIndex(e => e.StartTime);
builder.HasIndex(e => e.EventDefinitionId);
builder.HasIndex(e => e.SpecialEventType);
// Foreign key relationship (optional)
builder.HasOne(e => e.EventDefinition)
.WithMany()
.HasForeignKey(e => e.EventDefinitionId)
.OnDelete(DeleteBehavior.Restrict); // Don't cascade delete if EventDefinition is deleted
// Constraints
builder.Property(e => e.Name)
.IsRequired()
.HasMaxLength(200);
builder.Property(e => e.Time)
.IsRequired()
.HasMaxLength(100);
builder.Property(e => e.Date)
.IsRequired()
.HasMaxLength(100);
builder.Property(e => e.Location)
.HasMaxLength(500);
builder.Property(e => e.SpecialEventType)
.HasMaxLength(50);
// Validation: Either EventDefinitionId OR SpecialEventType must be set (enforced at application level)
// EF Core doesn't support mutually exclusive constraints directly, so we'll handle this in validation attributes or service layer
}
}
}