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?

1

1 Answer 1

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");
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.