In other providers such as Microsoft.EntityFrameworkCore.Sqlite or Pomelo.EntityFrameworkCore.MySql, you can implement it by calling UseSqlite() or UseMySql() without parameters.
That is, without connecting to a real database.
With Npgsql.EntityFrameworkCore.PostgreSQL and UseNpgsql(), I get the following error:
Unable to create a 'DbContext' of type 'MyDbContext'. The exception 'The ConnectionString property has not been initialized.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
Code:
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
public class MybContextContextFactory : IDesignTimeDbContextFactory<MyDbContext>
{
public MyDbContext CreateDbContext(string[] args)
{
DbContextOptionsBuilder<MyDbContext> dbContextOptionsBuilder = new();
dbContextOptionsBuilder.UseNpgsql();
return new MyDbContext(dbContextOptionsBuilder.Options);
}
}
Command:
dotnet ef dbcontext script --output Databas.sql
cc @roji
In other providers such as
Microsoft.EntityFrameworkCore.SqliteorPomelo.EntityFrameworkCore.MySql, you can implement it by callingUseSqlite()orUseMySql()without parameters.That is, without connecting to a real database.
With
Npgsql.EntityFrameworkCore.PostgreSQLandUseNpgsql(), I get the following error:Code:
Command:
cc @roji