How in EF6 using Code-First can you set the Datetime column to the default value for the current date of addition "statement_timestamp ()"? PostgreSql is used as a database.
namespace EFPostgresExperiments.model { [Table("Logs", Schema = "public")] public class Logs { [Key] public Int64 ID { get; set; } public String ErrorType { get; set; } public String Description { get; set; } public DateTime Date { get; set; } } public class LogsConfig : EntityTypeConfiguration<Logs> { public LogsConfig() { this.Property(p => p.ID).HasColumnName("ID"); this.Property(p => p.ErrorLevel).HasColumnName("ErrorType").IsRequired(); this.Property(p => p.Description).HasColumnName("Description").IsRequired(); this.Property(p => p.Date).HasColumnName("Date").IsRequired(); } } }
UPD:
At the moment, only the solution has been found using direct queries immediately after creating the database. But of course I would like less aggressive methods from the built-in EF tools.
namespace EFPostgresExperiments.model { public PGContext() : base("PGDatabase") { if (!this.Database.Exists()) { this.Database.Create(); this.Database.ExecuteSqlCommand("ALTER TABLE \"Logs\" ALTER COLUMN \"Date\" SET DEFAULT statement_timestamp()"); } } }