Open suugbut opened 10 months ago
hmmm thanks for reporting this issue, will take a look soon
@suugbut I have same issue and resolved by following instructions from https://learn.microsoft.com/en-us/ef/core/cli/dbcontext-creation?tabs=dotnet-core-cli Below is my example.
public class AppDbContextContextFactory : IDesignTimeDbContextFactory<AppDbContext>
{
public AppDbContext CreateDbContext(string[] args)
{
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build();
var connectionString = configuration.GetConnectionString("DefaultConnection");
var optionsBuilder = new DbContextOptionsBuilder<AppDbContext>();
optionsBuilder.UseNpgsql(connectionString);
return new AppDbContext(optionsBuilder.Options);
}
}
@sunkeun-choi
@suugbut I have same issue and resolved by following instructions from https://learn.microsoft.com/en-us/ef/core/cli/dbcontext-creation?tabs=dotnet-core-cli Below is my example.
public class AppDbContextContextFactory : IDesignTimeDbContextFactory<AppDbContext> { public AppDbContext CreateDbContext(string[] args) { var configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json") .Build(); var connectionString = configuration.GetConnectionString("DefaultConnection"); var optionsBuilder = new DbContextOptionsBuilder<AppDbContext>(); optionsBuilder.UseNpgsql(connectionString); return new AppDbContext(optionsBuilder.Options); } }
In which project did you put this? I have 4 projects. Have you tested? We are talking the same scenario or not?
My repo at https://github.com/suugbut/CodegenBug provides some batch files to generate the solution and many more. Here I just pasted the problem description from it.
To illustrate the problem, I make 4 projects as follows:
Model
project with one entity modelUser.cs
Context
project with one database contextAppDbContext.cs
MigrationForSqlite
project with a trivial classEmpty.cs
This project is used to keep migration files generated by ef tool for specific db provider (in this case for sqlite).
Api
project withProgram.cs
I successfully did the following:
dotnet ef migrations add Initializaiton -s Api -p MigrationForSqlite
dotnet ef database update -s Api
dotnet run --project Api --launch-profile https
https://localhost:7255
that producesHello World
After shutting the server down, I attempted to scaffold endpoints for
User
model with the following batch file but I failed.The error messages are: