我想在列中插入一个Eastern Time Zone
之类的值,但在该列中没有任何值。在下面的代码中,我尝试插入默认值,但未成功:
[MaxLength(150), DefaultValue("Eastern Time Zone")]
public string Timezone { get; set; }
您能帮我插入默认值吗?
您可以通过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");
}