39 lines
1.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using RAG.Domain.Entities;
namespace RAG.Infrastructure.Persistence.Configurations;
public class PermissionConfiguration : IEntityTypeConfiguration<Permission>
{
public void Configure(EntityTypeBuilder<Permission> 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);
}
}