PostFileConfiguration.cs 912 B

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