CommentFileConfiguration.cs 1.1 KB

123456789101112131415161718192021222324
  1. using Domain.Entities.Forum.Comments;
  2. using Microsoft.EntityFrameworkCore;
  3. using Microsoft.EntityFrameworkCore.Metadata.Builders;
  4. namespace Infrastructure.Persistence.Configurations.Forum.Comments;
  5. public sealed class CommentFileConfiguration : IEntityTypeConfiguration<CommentFile>
  6. {
  7. public void Configure(EntityTypeBuilder<CommentFile> builder)
  8. {
  9. builder.HasIndex(x => x.BoardID);
  10. builder.HasIndex(x => x.PostID);
  11. builder.HasIndex(x => x.CommentID);
  12. builder.HasIndex(x => x.UUID).IsUnique();
  13. builder.HasOne(x => x.Board).WithMany().HasForeignKey(x => x.BoardID).OnDelete(DeleteBehavior.Restrict);
  14. builder.HasOne(x => x.Post).WithMany().HasForeignKey(x => x.PostID).OnDelete(DeleteBehavior.Restrict);
  15. builder.HasOne(x => x.Comment).WithMany(x => x.CommentFile).HasForeignKey(x => x.CommentID).OnDelete(DeleteBehavior.Cascade);
  16. builder.ToTable("CommentFile", x => x.HasComment("댓글 파일"));
  17. builder.HasKey(x => x.ID);
  18. builder.Property(x => x.ID).ValueGeneratedOnAdd().HasComment("PK");
  19. }
  20. }