KoogleApp/src/Koogle.Infrastructure/Data/Configurations/BookingCategoryConfiguratio...

59 lines
1.6 KiB
C#

using Koogle.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Koogle.Infrastructure.Data.Configurations;
/// <summary>
/// EF Core configuration for BookingCategory entity.
/// </summary>
public class BookingCategoryConfiguration : IEntityTypeConfiguration<BookingCategory>
{
public void Configure(EntityTypeBuilder<BookingCategory> builder)
{
builder.ToTable("BookingCategories");
builder.HasKey(x => x.Id);
builder.Property(x => x.ClubId)
.IsRequired();
builder.Property(x => x.Name)
.HasMaxLength(100)
.IsRequired();
builder.Property(x => x.Description)
.HasMaxLength(500);
builder.Property(x => x.CategoryType)
.HasConversion<int>()
.IsRequired();
builder.Property(x => x.IsSystemCategory)
.IsRequired();
builder.Property(x => x.Color)
.HasMaxLength(7); // #RRGGBB
builder.Property(x => x.Icon)
.HasMaxLength(50);
builder.Property(x => x.IsActive)
.IsRequired();
builder.HasOne(x => x.Club)
.WithMany(c => c.BookingCategories)
.HasForeignKey(x => x.ClubId)
.OnDelete(DeleteBehavior.NoAction);
builder.HasAlternateKey(x => new { x.Id, x.ClubId });
builder.HasIndex(x => x.ClubId);
builder.HasIndex(x => new { x.ClubId, x.Name })
.HasFilter("[IsDeleted] = 0")
.IsUnique();
builder.HasQueryFilter(x => !x.IsDeleted);
}
}