I am not really clear on why the error happens. When I first scaffold my project the migration and update-database commands ran fine but after few changes in the application I was getting this error. The only solution floating around is this:
public class BloggingContextFactory : IDbContextFactory<BloggingContext>
{
public BloggingContext Create()
{
var optionsBuilder = new DbContextOptionsBuilder<BloggingContext>();
optionsBuilder.UseSqlite("Data Source=blog.db");
return new BloggingContext(optionsBuilder.Options);
}
}
My DbContext:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>, IApplicationDbContext
{
public DbSet<ApplicationUserCode> ApplicationUserCodes { get; set; }
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
// Customize the ASP.NET Identity model and override the defaults if needed.
// For example, you can rename the ASP.NET Identity table names and more.
// Add your customizations after calling base.OnModelCreating(builder);
}
}
It works for me but the connection string is hard-coded inside the class which is not fine with me. Any clarifications as to why this error did not happen at one time and later it did is really appreciated and also a elegant solution than embedding connection string in class please.