So I have a problem with Migrations in EF. I am trying to familiarize myself with an older WPF project and I have done some restructuring. I moved my Context to a class library that has the common code
namespace WPFDemoApp.Common.Context
{
public class ApplicationDbContext<TEntity> : DbContext where TEntity : class
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext<TEntity>> options)
: base(options)
{
}
public DbSet<TEntity> Entities { get; set; }
}
public class ApplicationDbContextFactory<TEntity> : IDesignTimeDbContextFactory<ApplicationDbContext<TEntity>> where TEntity : class
{
public ApplicationDbContext<TEntity> CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<ApplicationDbContext<TEntity>>();
optionsBuilder.UseSqlite("Data Source=localdatabase.db");
return new ApplicationDbContext<TEntity>(optionsBuilder.Options);
}
}
}
It is registered in a diffrent project
namespace WPFDemoApp
{
public static class ServiceRegistration
{
public static IServiceProvider ConfigureServices()
{
var services = new ServiceCollection();
// Register services here
services.AddDbContext<ApplicationDbContext<ToDoItem>>(
options => options.UseSqlite("Data Source=localdatabase.db"));
services.AddScoped<MainWindow>();
services.AddScoped<ToDoItem>();
services.AddScoped<IRepository<ToDoItem>, Repository<ToDoItem>>();
services.AddScoped<IGetAllDataUseCase<ToDoItem>, GetAllDataUseCase<ToDoItem>>();
services.AddScoped<MainViewModel<ToDoItem>>();
// Add other services
return services.BuildServiceProvider();
}
}
}
And when I am using the
Anyone knows why ?
I have tried running different commands but the older WPF structure is giving me a headache.