using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using MyHN.Domain; namespace MyHN.Infrastructure.EntityTypes { public class CommentEntityType : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { builder.ToTable("comments"); builder.HasKey(o => o.Id); builder.Property(o => o.Content).IsRequired(); builder.Property(o => o.CreatedAt).IsRequired(); builder.HasOne() .WithMany() .HasForeignKey(o => o.LinkId) .IsRequired() .OnDelete(DeleteBehavior.Cascade); builder.OwnsMany(o => o.Votes, vote => { vote.ToTable("comment_votes"); vote.WithOwner().HasForeignKey("CommentId"); vote.HasOne() .WithMany() .HasForeignKey(o => o.CreatedBy) .IsRequired() .OnDelete(DeleteBehavior.Cascade); vote.HasKey("CommentId", nameof(Vote.CreatedBy)); vote.Property(o => o.Direction).IsRequired(); vote.Property(o => o.CreatedAt).IsRequired(); }); } } }