PostMediaConfiguration.cs 870 B

123456789101112131415161718192021
  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 PostMediaConfiguration : IEntityTypeConfiguration<PostMedia>
  6. {
  7. public void Configure(EntityTypeBuilder<PostMedia> builder)
  8. {
  9. builder.HasIndex(x => x.BoardID);
  10. builder.HasIndex(x => x.PostID);
  11. builder.HasOne(x => x.Board).WithMany().HasForeignKey(x => x.BoardID).OnDelete(DeleteBehavior.Restrict);
  12. builder.HasOne(x => x.Post).WithMany(x => x.PostMedia).HasForeignKey(x => x.PostID).OnDelete(DeleteBehavior.Cascade);
  13. builder.ToTable("PostMedia", x => x.HasComment("게시글 미디어"));
  14. builder.HasKey(x => x.ID);
  15. builder.Property(x => x.ID).ValueGeneratedOnAdd().HasComment("PK");
  16. }
  17. }