0

I want to insert in a column a value like Eastern Time Zone but I didn't get any value in the column. In the code below I try, unsuccessfully, to insert a default value:

 [MaxLength(150), DefaultValue("Eastern Time Zone")]
 public string Timezone { get; set; } 

Could you please help me to insert a default value?

David Buck
  • 3,752
  • 35
  • 31
  • 35
Rani
  • 9
  • 4
  • Can you please check this link https://stackoverflow.com/questions/19554050/entity-framework-6-code-first-default-value/27920032 – jishan siddique Feb 06 '20 at 06:25

1 Answers1

1

You can use the following from the fluent API: https://www.learnentityframeworkcore.com/configuration/fluent-api/hasdefaultvaluesql-method

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<YourEntity>()
        .Property(b => b.Timezone)
        .HasDefaultValueSql("Eastern Time Zone");
}
Athanasios Kataras
  • 25,191
  • 4
  • 32
  • 61