using SqlSugar; using System; using System.ComponentModel.DataAnnotations.Schema; namespace WCS.Entity { /// /// 实体类通用基础类 /// [Serializable] public abstract class OBJ { /// /// ID /// [SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnDescription = "ID")] [Column(Order = 0)] public virtual int ID { get; set; } /// /// 是否可用 /// [SugarColumn(ColumnDescription = "是否可用")] public bool Enabled { get; set; } = true; /// /// 创建用户 /// 仅记录用户ID /// [SugarColumn(ColumnDescription = "创建用户", Length = 50)] public string AddWho { get; set; } /// /// 创建时间 /// 新增数据时自动获取服务器时间 /// [SugarColumn(ColumnDescription = "创建时间", InsertServerTime = true)] public virtual DateTime AddTime { get; set; } /// /// 更新用户 /// 仅记录用户ID /// [SugarColumn(ColumnDescription = "更新用户", Length = 50, IsNullable = true)] public string EditWho { get; set; } /// /// 更新时间 /// 更新数据时自动获取服务器时间 /// [SugarColumn(ColumnDescription = "更新时间", UpdateServerTime = true, IsNullable = true)] public DateTime EditTime { get; set; } /// /// 版本号 /// [SugarColumn(ColumnDescription = "版本号", ColumnDataType = "timestamp", IsNullable = true, IsOnlyIgnoreInsert = true, IsOnlyIgnoreUpdate = true)] public byte[] VER { get; set; } /// /// /// /// /// public T Copy() where T : OBJ { var instance = Activator.CreateInstance(); foreach (var property in GetType().GetProperties()) { var obj = property.GetValue(this); typeof(T).GetProperty(property.Name)!.SetValue(instance, obj); } return instance; } } }