我希望将数据保存在我的应用程序上,但是我得到
InvalidOperationException,“尚未为此DbContext配置数据库提供程序。”
我的代码在下面
public IActionResult Create(ProjectViewModel viewModel)
{
ApplicationDbContext dbContext = new ApplicationDbContext(new Microsoft.EntityFrameworkCore.DbContextOptions<ApplicationDbContext>());
dbContext.Project.Add(new Project()
{
ProjectName = viewModel.ProjectName,
ProjectStart = viewModel.StartDate,
ProjectEnd = viewModel.DeadLine,
Priority = viewModel.Priority,
Target = viewModel.Target,
ProjectDescription = viewModel.Description,
ProjectParts = viewModel.Amountofparts
});
dbContext.SaveChanges();
return View(nameof(NewProject));
}
我该如何解决它,任何帮助将不胜感激。
答案 0 :(得分:0)
需要按照以下https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity?view=aspnetcore-2.1&tabs=visual-studio的方式将dbContext添加到服务中 或者您需要在声明中指定连接字符串