using Lada.Framework.Data.Domains.Cms;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Lada.Framework.Data.Mappings.EntityMappings.Cms
{
    public class PostCategoryMap : IEntityMappingConfiguration<PostCategory>
    {
        public void Map(EntityTypeBuilder<PostCategory> builder)
        {
            builder.HasKey(pc => new { pc.PostId, pc.CategoryId});
            builder.HasOne(pc => pc.Post).WithMany(p => p.PostCategories).HasForeignKey(pc => pc.PostId);
            builder.HasOne(pc => pc.Category).WithMany(p => p.PostCategories).HasForeignKey(pc => pc.CategoryId);
            builder.ToTable("PostCategory");
        }
    }
}
