You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.6 KiB
43 lines
1.6 KiB
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
using CellularManagement.Domain.Abstractions;
|
|
|
|
namespace CellularManagement.Infrastructure.Configurations;
|
|
|
|
/// <summary>
|
|
/// 基础实体配置类
|
|
/// 包含审计字段的通用配置,为所有可审计实体提供统一的数据库映射配置
|
|
/// </summary>
|
|
/// <typeparam name="TEntity">实体类型,必须继承自 AuditableEntity</typeparam>
|
|
public abstract class BaseEntityConfiguration<TEntity> : IEntityTypeConfiguration<TEntity>
|
|
where TEntity : AuditableEntity
|
|
{
|
|
/// <summary>
|
|
/// 配置基础实体
|
|
/// 设置实体的主键和审计字段的数据库映射
|
|
/// </summary>
|
|
/// <param name="builder">实体类型构建器,用于配置实体的数据库映射</param>
|
|
public virtual void Configure(EntityTypeBuilder<TEntity> 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);
|
|
}
|
|
}
|