Tell EF to automatically compute and insert the current date time when the row is created?
问题 I want to insert current Datetime when ever a new row is inserted. I am using Code First Approach of EF 6,MVC 5 After searching I got this [DatabaseGenerated(DatabaseGeneratedOption.Computed)] public DateTime? CreatedDate { get; set; } It has to be written in Models Class,but when ever a new record is inserted NULL is saved in DB,I have noticed that this is just declaration of CreatedDate,where to write CreatedDate = DateTime.Now OR any other way to solve it. My Entire Model namespace