using System; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace VCommon.VEntity { public abstract class VEntityBase { private string _keyField; //EF Core Trick? must difference with prop name for init [Key, MinLength(36), MaxLength(36), DatabaseGenerated(DatabaseGeneratedOption.None)] public string Id { get { if (string.IsNullOrWhiteSpace(_keyField)) _keyField = Guid.NewGuid().ToString(); return _keyField; } set => _keyField = value; } } }