VEntityBase.cs 487 B

12345678910111213141516171819
  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 Guid? _keyField; //EF Core Trick? must difference with prop name for init
  9. [Key]
  10. [DatabaseGenerated(DatabaseGeneratedOption.None)]
  11. public Guid Id
  12. {
  13. get => _keyField ??= Guid.NewGuid();
  14. set => _keyField = value;
  15. }
  16. }
  17. }