I'm trying to do a sample on ef core 2 but I'm getting the following when I try to add migrations
PM> Add-Migration InitialCreate
No parameterless constructor was found on 'ToDoContext'. Either add a parameterless constructor to 'ToDoContext' or add an implementation of 'IDbContextFactory<ToDoContext>' in the same assembly as 'ToDoContext'.
I followed this tutorial https://learn.microsoft.com/en-us/ef/core/get-started/aspnetcore/new-db Here is my code.
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
var connection = @"Server=(localdb)\mssqllocaldb;Database=EFGetStarted.AspNetCore.NewDb;Trusted_Connection=True;";
services.AddDbContext<ToDoContext>(options => options.UseSqlServer(connection));
services.AddMvc();
}
}
public class ToDoContext : DbContext
{
public ToDoContext(DbContextOptions<ToDoContext> options)
: base(options)
{
}
public DbSet<ToDo> ToDos { get; set; }
}
public class ToDo
{
public int Id { get; set; }
public string Title { get; set; }
public bool Completed { get; set; }
}