PostBookmarkConfiguration.cs 1.1 KB

123456789101112131415161718192021222324
  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 PostBookmarkConfiguration : IEntityTypeConfiguration<PostBookmark>
  6. {
  7. public void Configure(EntityTypeBuilder<PostBookmark> builder)
  8. {
  9. builder.HasIndex(x => x.BoardID);
  10. builder.HasIndex(x => x.PostID);
  11. builder.HasIndex(x => x.MemberID);
  12. builder.HasIndex(x => new { x.PostID, x.MemberID }).IsUnique();
  13. builder.HasOne(x => x.Board).WithMany().HasForeignKey(x => x.BoardID).OnDelete(DeleteBehavior.Restrict);
  14. builder.HasOne(x => x.Post).WithMany(x => x.PostBookmark).HasForeignKey(x => x.PostID).OnDelete(DeleteBehavior.Cascade);
  15. builder.HasOne(x => x.Member).WithMany().HasForeignKey(x => x.MemberID).OnDelete(DeleteBehavior.Cascade);
  16. builder.ToTable("PostBookmark", x => x.HasComment("게시글 즐겨찾기"));
  17. builder.HasKey(x => x.ID);
  18. builder.Property(x => x.ID).ValueGeneratedOnAdd().HasComment("PK");
  19. }
  20. }