How to automatically populate CreatedDate and ModifiedDate?

后端 未结 6 2102
失恋的感觉
失恋的感觉 2021-01-31 17:07

I am learning ASP.NET Core MVC and my model is

namespace Joukyuu.Models
{
    public class Passage
    {
        public int PassageId { get; set; }
        publi         


        
6条回答
  •  你的背包
    2021-01-31 17:32

    Solution for CreationDate in PostgreSQL:

    builder.Property(e => e.CreationDate)
      .HasColumnType("timestamp without time zone")
      .HasDefaultValueSql("NOW()")
      .ValueGeneratedOnAdd();
    

    via: https://www.npgsql.org/efcore/modeling/generated-properties.html#guiduuid-generation Unfortunately there is not solution for update event

提交回复
热议问题