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:
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user