Answer the question
In order to leave comments, you need to log in
ASP.NET Core. Why are records not saved in the database?
My head boils all day from these connections to the database.
Connection:
"ConnectionStrings": {
"DefaultConnection": "Server=(LocalDb)\\MSSQLLocalDB; Database=EmployeesDatabase; Trusted_Connection=True;"
},
string connection = Configuration.GetConnectionString("DefaultConnection");
services.AddDbContext<AppDbContext>(x => x.UseSqlServer(connection));
public DbSet<Employee> Employees { get; set; }
public AppDbContext(DbContextOptions<AppDbContext> options)
: base(options)
{
Database.EnsureCreated();
}
public IActionResult AddEmployee(Employee employee)
{
db.Employees.Add(employee);
db.SaveChanges();
return RedirectToAction("Index");
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question