I got following error when trying to run the migrations on a .NET Core 6 Web API.
Unable to create an object of type 'MyDBContext'
After tarting out different approaches following changes made migrations work.
1. MyDbContext
public class MyDbContext : DbContext, IMyDbContext
{
public MyDbContext()
{
}
public MyDbContext(DbContextOptions<MyDbContext> options) : base(options)
{
protected override void OnConfiguring(DbContextOptionsBuilder
optionsBuilder)
{
optionsBuilder.UseSqlServer("Data Source=localhost;Initial Catalog = Library;Integrated Security=True;Trusted_Connection=True;TrustServerCertificate=True");
}
//...more code
}
2. Program.cs
builder.Services.ConfigureLoggerService();
//more options
options.UseSqlServer(builder.Configuration.GetConnectionString
("DefaultConnection")));
Cheers,
Samitha
No comments:
Post a Comment