Search code examples
c#.netentity-frameworkentitydotnet-aspire

.NET Aspire EF, can't make initial database update


I make my database in .NET Aspire in AppHost project like this:

var db = builder.AddPostgres("db").WithPgAdmin();
var templateApiDb = db.AddDatabase("templateApiDb");

var apiService = builder.AddProject<Projects.AspireSample_ApiService>("apiservice")
    .WithReference(templateApiDb);

In my ApiService project, I wrote this:

builder.AddNpgsqlDbContext<AppDbContext>("templateApiDb");

And when I run AppHost, it creates the database, but with no structure, because before I used .NET Aspire, I did it thru this command:

dotnet ef database update

Please - how can I update structure of my database in this case?

Run database in .NET Aspire with EF but I always have empty database with no structure.


Solution

  • Check out https://github.com/dotnet/aspire-samples/tree/main/samples/DatabaseMigrations for an example on how to do this.