这个错误通常表示在使用Entity Framework Core时,上下文类型(DatenbankKontext)中只声明了一个无参数的构造函数,但是Entity Framework Core需要一个带有参数的构造函数来注入依赖项。
要解决这个问题,您可以按照以下步骤进行操作:
public class DatenbankKontext : DbContext
{
public DatenbankKontext(DbContextOptions options) : base(options)
{
}
// 其他代码...
}
public void ConfigureServices(IServiceCollection services)
{
// 其他配置...
services.AddDbContext(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
// 其他配置...
}
{
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=MyDatabase;Trusted_Connection=True;MultipleActiveResultSets=true"
},
// 其他配置...
}
请确保将上面的连接字符串替换为您自己的数据库连接字符串。
通过遵循上述步骤,您应该能够解决这个问题,并让您的ASP.NET Core MVC应用程序与Entity Framework Core一起正常工作。