DesignTimeContextFactories.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #if TOOLS
  2. using Microsoft.EntityFrameworkCore;
  3. using Microsoft.EntityFrameworkCore.Design;
  4. using SQLitePCL;
  5. // ReSharper disable UnusedType.Global
  6. namespace Content.Server.Database;
  7. public sealed class DesignTimeContextFactoryPostgres : IDesignTimeDbContextFactory<PostgresServerDbContext>
  8. {
  9. public PostgresServerDbContext CreateDbContext(string[] args)
  10. {
  11. var optionsBuilder = new DbContextOptionsBuilder<PostgresServerDbContext>();
  12. optionsBuilder.UseNpgsql("Server=localhost");
  13. return new PostgresServerDbContext(optionsBuilder.Options);
  14. }
  15. }
  16. public sealed class DesignTimeContextFactorySqlite : IDesignTimeDbContextFactory<SqliteServerDbContext>
  17. {
  18. public SqliteServerDbContext CreateDbContext(string[] args)
  19. {
  20. #if !USE_SYSTEM_SQLITE
  21. raw.SetProvider(new SQLite3Provider_e_sqlite3());
  22. #endif
  23. var optionsBuilder = new DbContextOptionsBuilder<SqliteServerDbContext>();
  24. optionsBuilder.UseSqlite("Data Source=:memory:");
  25. return new SqliteServerDbContext(optionsBuilder.Options);
  26. }
  27. }
  28. #endif