@CodeXennial , you could try the following code to set the default value in code first.
public class Student
{
[Key]
public int Id { get; set; }
public int PostStatusID { get; set; }
public string Name { get; set; }
}
public class StudentContext:DbContext
{
public DbSet<Student> students { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Student>()
.Property(b => b.PostStatusID)
.HasDefaultValue(-1);
}
protected override void OnConfiguring(DbContextOptionsBuilder builder)
{
builder.UseSqlServer("connstr");
}
}
Result in database design:
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.