OBJ.cs 1.2 KB

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