using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using RAG.Domain.Entities; namespace RAG.Infrastructure.Persistence.Configurations; public class PermissionConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { builder.ToTable("permissions"); builder.HasKey(p => p.Id); builder.Property(p => p.Id).ValueGeneratedNever().HasComment("权限ID"); builder.Property(p => p.Name).HasMaxLength(100).IsRequired().HasComment("权限名称"); builder.Property(p => p.Code).HasMaxLength(50).IsRequired().HasComment("权限编码,如 user:create,唯一"); builder.Property(p => p.Description).HasMaxLength(200).HasComment("权限描述"); builder.Property(p => p.Group).HasMaxLength(50).HasComment("权限分组"); // IAuditable builder.Property(p => p.CreatedBy).HasMaxLength(100).HasComment("创建人"); builder.Property(p => p.CreatedAt).HasComment("创建时间"); builder.Property(p => p.UpdatedBy).HasMaxLength(100).HasComment("更新人"); builder.Property(p => p.UpdatedAt).HasComment("更新时间"); // ISoftDelete builder.Property(p => p.IsDeleted).HasDefaultValue(false).HasComment("是否已软删除"); // IHasOperatorIP builder.Property(p => p.OperatorIP).HasMaxLength(50).HasComment("操作者IP地址"); builder.HasIndex(p => p.Code).IsUnique(); builder.HasMany(p => p.RolePermissions) .WithOne(rp => rp.Permission) .HasForeignKey(rp => rp.PermissionId) .OnDelete(DeleteBehavior.Cascade); } }