Files
Khwezi Mngoma 902942eee6
continuous-integration/drone/pr Build is passing
Completed initial database design
Sealed qualifying public classes
Migrated database changes
2026-05-27 09:12:04 +02:00

29 lines
1.1 KiB
C#

namespace LiteCharms.Features.MidrandBooks.AuthorBooks.Entities;
public sealed class AuthorBookConfiguration : IEntityTypeConfiguration<AuthorBook>
{
public void Configure(EntityTypeBuilder<AuthorBook> builder)
{
builder.ToTable("Books");
builder.HasKey(f => f.AuthorId);
builder.Property(f => f.CreatedAt).IsRequired().ValueGeneratedOnAdd().HasDefaultValueSql("now()");
builder.Property(f => f.UpdatedAt).HasDefaultValueSql("now()");
builder.Property(f => f.AuthorId).IsRequired();
builder.Property(f => f.ProductId).IsRequired();
builder.Property(f => f.Rating).IsRequired(false);
builder.Property(f => f.Ranking).IsRequired(false);
builder.Property(f => f.Enabled).HasDefaultValue(true);
builder.HasOne(f => f.Author)
.WithMany(a => a.Books)
.HasForeignKey(f => f.AuthorId)
.OnDelete(DeleteBehavior.Restrict);
builder.HasOne(f => f.Product)
.WithMany()
.HasForeignKey(f => f.ProductId)
.OnDelete(DeleteBehavior.Restrict);
}
}