Skip to content

Write guidance for using Entity Framework migrations with Aspire solutions #64

@gameraliaz

Description

@gameraliaz

Type of issue

Missing information

Description

my AppHost program.cs:

var builder = DistributedApplication.CreateBuilder(args);

var sql = builder.AddSqlServerContainer("sql",password:"P4s$wordBuT$tr0ng",port:14420).AddDatabase("sqldata");

builder.AddProject<Projects.adminendpoint>("admin").WithReference(sql);

builder.Build().Run();

Then i want to run it but first make database from my dbcontext that used in admin endpoint.
admin endpoint program.cs is:

builder.AddSqlServerDbContext<DataBaseContext>("sqldata");
builder.Services.AddScoped<IDataBaseContext, DataBaseContext>();

and my dbcontext is :

public class DataBaseContext : DbContext, IDataBaseContext
{
    public DataBaseContext(DbContextOptions dbContextOptions):base(dbContextOptions) { }
    public DbSet<User> Users { get; set; }
    public DbSet<Role> Roles { get; set; }
    public DbSet<UserInRole> UserInRoles { get; set; }
}

So how should i use Add-Migration and Update-Database?

Page URL

https://learn.microsoft.com/en-us/dotnet/aspire/database/sql-server-entity-framework-component?tabs=dotnet-cli

Content source URL

https://github.com/dotnet/docs-aspire/blob/main/docs/database/sql-server-entity-framework-component.md

Document Version Independent Id

2cd52f56-0ee5-8f04-c2b5-fe52c7f8109f

Article author

IEvangelist


Associated WorkItem - 186558

Metadata

Metadata

Assignees

Labels

📌 seQUESTeredIdentifies that an issue has been imported into Quest.Pri1High priority, do before Pri2 and Pri3databaseContent related to database.doc-enhancementImprove the current content [org][type][category]help wantedGood for community contributors to help [up-for-grabs]

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions