I am trying to add a model (table) to a SQL Server database, but I am getting an error.
Here is what I tried - in program.cs:
builder.Services.AddDbContext<DataContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("Default")));
In appsettings.json I have:
"ConnectionStrings": {
"Default": "Server=RWAHDAN;Database=HSPA2024;Integrated Security=False;User Id=sa; Password=mypassword;"
},
And this is my City model class:
public class City
{
public int Id { get; set; }
public string Name { get; set; }
}
Lastly I have my datacontext:
public class DataContext : DbContext
{
public DataContext(DbContextOptions<DataContext> options): base(options) {}
public DbSet<City> Cities { get; set; }
}
Migration is ok but updating database is not.