OBJ.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using SqlSugar;
  2. using System;
  3. using System.ComponentModel.DataAnnotations;
  4. using System.ComponentModel.DataAnnotations.Schema;
  5. namespace WCS.Entity
  6. {
  7. [Serializable]
  8. public abstract class OBJ
  9. {
  10. [SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnDescription = "ID")]
  11. [Column(Order = 0)]
  12. [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  13. [Display(Name = "主键", Order = 0)]
  14. [Key]
  15. public virtual int ID { get; set; }
  16. [SugarColumn(ColumnDescription = "是否可用")]
  17. [Display(Name = "可用")]
  18. public bool ENABLED { get; set; } = true;
  19. [SugarColumn(ColumnDescription = "是否可用", Length = 50, IsNullable = true)]
  20. [Display(Name = "更新者")]
  21. [MaxLength(50)]
  22. [Required]
  23. public string UPDATEUSER { get; set; }
  24. [SugarColumn(ColumnDescription = "更新时间")]
  25. [Display(Name = "更新时间")]
  26. public DateTime UPDATETIME { get; set; } = DateTime.Now;
  27. [SugarColumn(ColumnDescription = "更新时间")]
  28. [Timestamp]
  29. [Display(Name = "版本")]
  30. public byte[] VER { get; set; }
  31. public T Copy<T>() where T : OBJ
  32. {
  33. var instance = Activator.CreateInstance<T>();
  34. foreach (var property in GetType().GetProperties())
  35. {
  36. var obj = property.GetValue(this);
  37. typeof(T).GetProperty(property.Name)!.SetValue(instance, obj);
  38. }
  39. return instance;
  40. }
  41. }
  42. }