C
C#2y ago
demndev

✅ Build failed on `dotnet-ef database update`

10 Replies
FusedQyou
FusedQyou2y ago
Did you build and try the command afterwards? Can we see the code up to the point where you call AddDbContext?
demndev
demndev2y ago
yes:
public static IServiceCollection AddPersistence(this IServiceCollection services, IConfiguration configuration)
{
var connection = configuration.GetConnectionString("DefaultConnection")
?? throw new Exception("Unable to parse DbConnection configuration");
services.AddDbContext<IApplicationContext, ApplicationContext>(options => options.UseSqlite(connection));


return services;
}
public static IServiceCollection AddPersistence(this IServiceCollection services, IConfiguration configuration)
{
var connection = configuration.GetConnectionString("DefaultConnection")
?? throw new Exception("Unable to parse DbConnection configuration");
services.AddDbContext<IApplicationContext, ApplicationContext>(options => options.UseSqlite(connection));


return services;
}
FusedQyou
FusedQyou2y ago
And up to where you call AddPersistence?
demndev
demndev2y ago
var builder = WebApplication.CreateBuilder(args);
{
builder.Services
.AddApplication()
.AddPersistence(builder.Configuration)
.AddWeb(builder.Configuration);
}
var builder = WebApplication.CreateBuilder(args);
{
builder.Services
.AddApplication()
.AddPersistence(builder.Configuration)
.AddWeb(builder.Configuration);
}
FusedQyou
FusedQyou2y ago
Maybe try removing {}
demndev
demndev2y ago
no, but it builds when I call database update:
Build started...
Build started...
FusedQyou
FusedQyou2y ago
I believe EF injects code up to AddDbContext and it might not be able to properly do that
demndev
demndev2y ago
all the same
demndev
demndev2y ago
and again there's nothing helpful
demndev
demndev2y ago
miraculously the problem solved itself