using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using CellularManagement.Domain.Abstractions; namespace CellularManagement.Infrastructure.Configurations; /// /// 基础实体配置类 /// 包含审计字段的通用配置,为所有可审计实体提供统一的数据库映射配置 /// /// 实体类型,必须继承自 AuditableEntity public abstract class BaseEntityConfiguration : IEntityTypeConfiguration where TEntity : AuditableEntity { /// /// 配置基础实体 /// 设置实体的主键和审计字段的数据库映射 /// /// 实体类型构建器,用于配置实体的数据库映射 public virtual void Configure(EntityTypeBuilder builder) { // 配置主键 // 使用 Id 作为实体的主键 builder.HasKey(e => e.Id); // 配置审计字段 // 创建时间:必填字段,记录实体的创建时间 builder.Property(e => e.CreatedAt) .IsRequired(); // 更新时间:必填字段,记录实体的最后更新时间 builder.Property(e => e.UpdatedAt) .IsRequired(); // 创建人:可选字段,最大长度256,记录创建实体的用户ID builder.Property(e => e.CreatedBy) .HasMaxLength(256); // 更新人:可选字段,最大长度256,记录最后更新实体的用户ID builder.Property(e => e.UpdatedBy) .HasMaxLength(256); } }