VEntityBase.cs 637 B

12345678910111213141516171819202122
  1. using System;
  2. using System.ComponentModel.DataAnnotations;
  3. using System.ComponentModel.DataAnnotations.Schema;
  4. namespace VCommon.VEntity
  5. {
  6. public abstract class VEntityBase
  7. {
  8. private string _keyField; //EF Core Trick? must difference with prop name for init
  9. [Key, MinLength(36), MaxLength(36), DatabaseGenerated(DatabaseGeneratedOption.None)]
  10. public string Id
  11. {
  12. get
  13. {
  14. if (string.IsNullOrWhiteSpace(_keyField)) _keyField = Guid.NewGuid().ToString();
  15. return _keyField;
  16. }
  17. set => _keyField = value;
  18. }
  19. }
  20. }