using SqlSugar; using System; using System.ComponentModel.DataAnnotations; namespace Magic.Core.Entity; /// /// 自定义实体基类 /// [Tenant(CommonConst.MasterDb)] public abstract class DEntityBase : PrimaryKeyEntity { /// /// 创建时间 /// [SugarColumn(ColumnDescription = "创建时间", IsNullable = true)] public virtual DateTime? CreatedTime { get; set; } /// /// 更新时间 /// [SugarColumn(ColumnDescription = "更新时间", IsNullable = true)] public virtual DateTime? UpdatedTime { get; set; } /// /// 创建者Id /// [SugarColumn(ColumnDescription = "创建者Id", IsNullable = true)] public virtual long? CreatedUserId { get; set; } /// /// 创建者名称 /// [MaxLength(20)] [SugarColumn(ColumnDescription = "创建者名称", IsNullable = true)] public virtual string CreatedUserName { get; set; } /// /// 修改者Id /// [SugarColumn(ColumnDescription = "修改者Id", IsNullable = true)] public virtual long? UpdatedUserId { get; set; } /// /// 修改者名称 /// [MaxLength(20)] [SugarColumn(ColumnDescription = "修改者名称", IsNullable = true)] public virtual string UpdatedUserName { get; set; } /// /// 软删除 /// [SugarColumn(ColumnDescription = "软删除")] public virtual bool IsDeleted { get; set; } = false; /// /// 更新信息列 /// /// public virtual string[] UpdateColumn() { var result = new[] {nameof(UpdatedUserId), nameof(UpdatedUserName), nameof(UpdatedTime)}; return result; } /// /// 假删除的列,包含更新信息 /// /// public virtual string[] FalseDeleteColumn() { var updateColumn = UpdateColumn(); var deleteColumn = new[] {nameof(IsDeleted)}; var result = new string [updateColumn.Length + deleteColumn.Length]; deleteColumn.CopyTo(result, 0); updateColumn.CopyTo(result, deleteColumn.Length); return result; } } /// /// 递增主键实体基类 /// public abstract class AutoIncrementEntity { /// /// 主键Id /// [SugarColumn(IsIdentity = true, ColumnDescription = "Id主键", IsPrimaryKey = true)] //通过特性设置主键和自增列 // 注意是在这里定义你的公共实体 public virtual int Id { get; set; } } /// /// 主键实体基类 /// public abstract class PrimaryKeyEntity { /// /// 主键Id /// [SugarColumn(ColumnDescription = "Id主键", IsPrimaryKey = true)] // 注意是在这里定义你的公共实体 public virtual long Id { get; set; } }