using HN.Domain; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace HN.Infrastructure { public sealed class CommentEntityType : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { builder.ToTable("comments"); builder.HasKey(o => o.Id); builder.HasOne() .WithMany() .HasForeignKey(o => o.LinkId) .IsRequired(); builder.Property(o => o.Content).IsRequired(); builder.Property(o => o.CreatedAt).IsRequired(); builder.OwnsMany(o => o.Votes, vote => { vote.ToTable("comment_votes"); vote.WithOwner().HasForeignKey("CommentId"); vote.HasKey("CommentId"); vote.Property(o => o.Type).IsRequired(); vote.Property(o => o.CreatedAt).IsRequired(); }); } } }