Files
OldThink/Content.Server.Database/DesignTimeContextFactories.cs

36 lines
1.0 KiB
C#
Raw Permalink Normal View History

2023-04-03 02:24:55 +02:00
#if TOOLS
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
2023-04-03 02:24:55 +02:00
using SQLitePCL;
// ReSharper disable UnusedType.Global
namespace Content.Server.Database;
public sealed class DesignTimeContextFactoryPostgres : IDesignTimeDbContextFactory<PostgresServerDbContext>
{
public PostgresServerDbContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<PostgresServerDbContext>();
optionsBuilder.UseNpgsql("Server=localhost");
return new PostgresServerDbContext(optionsBuilder.Options);
}
}
public sealed class DesignTimeContextFactorySqlite : IDesignTimeDbContextFactory<SqliteServerDbContext>
{
public SqliteServerDbContext CreateDbContext(string[] args)
{
2023-04-03 02:24:55 +02:00
#if !USE_SYSTEM_SQLITE
raw.SetProvider(new SQLite3Provider_e_sqlite3());
#endif
var optionsBuilder = new DbContextOptionsBuilder<SqliteServerDbContext>();
optionsBuilder.UseSqlite("Data Source=:memory:");
return new SqliteServerDbContext(optionsBuilder.Options);
}
}
2023-04-03 02:24:55 +02:00
#endif