Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gameraliaz opened this issue Nov 18, 2023 · 4 comments · May be fixed by #838
Open

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

gameraliaz opened this issue Nov 18, 2023 · 4 comments · May be fixed by #838
Assignees
Labels
database Content related to database. doc-enhancement Improve the current content [org][type][category] documentation Improvements or additions to documentation help wanted Good for community contributors to help [up-for-grabs] Pri1 High priority, do before Pri2 and Pri3 📌 seQUESTered Identifies that an issue has been imported into Quest.

Comments

@gameraliaz
Copy link

gameraliaz commented Nov 18, 2023

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

@davidfowl
Copy link
Member

Excellent question! This is one of the big problems we hit while developing eshop as well. Adding migrations requires putting a connection string in the appSettings.json or EF will blow up.

For update database, we for the first preview, we settled on a separate application that runs as part of the app:

https://github.com/dotnet/aspire/tree/main/samples/eShopLite/CatalogDb

See dotnet/aspire#398 for more info.

@peteraritchie
Copy link
Contributor

Excellent question! This is one of the big problems we hit while developing eshop as well. Adding migrations requires putting a connection string in the appSettings.json or EF will blow up.

So, the connection string in code will only be known to the other project at run-time. Even if the connection string was in the appsettings for AppHost, the other project would only know about the value at run-time, not at design-time (i.e. when using dotnet ef). Bummer.

@davidfowl
Copy link
Member

Yes this is a problem.

@IEvangelist
Copy link
Member

@davidfowl - I assume we need to call this out in docs? If so, what exactly should we say?

@IEvangelist IEvangelist self-assigned this Nov 27, 2023
@IEvangelist IEvangelist added documentation Improvements or additions to documentation question Further information is requested 🗺️ reQUEST Triggers an issue to be imported into Quest. Pri1 High priority, do before Pri2 and Pri3 labels Nov 27, 2023
@github-actions github-actions bot added 📌 seQUESTered Identifies that an issue has been imported into Quest. and removed 🗺️ reQUEST Triggers an issue to be imported into Quest. labels Nov 28, 2023
@adegeo adegeo added enhancement doc-enhancement Improve the current content [org][type][category] and removed enhancement question Further information is requested labels Dec 8, 2023
@IEvangelist IEvangelist removed their assignment Jan 11, 2024
@IEvangelist IEvangelist added the help wanted Good for community contributors to help [up-for-grabs] label Jan 18, 2024
@IEvangelist IEvangelist mentioned this issue Feb 21, 2024
@JamesNK JamesNK changed the title Add-Migration and Update-Database with SqlServerContainer Guidance for using Entity Framework migrations with Aspire solutions Mar 4, 2024
@JamesNK JamesNK changed the title Guidance for using Entity Framework migrations with Aspire solutions Write guidance for using Entity Framework migrations with Aspire solutions Mar 4, 2024
@CamSoper CamSoper added the database Content related to database. label Mar 19, 2024
@CamSoper CamSoper linked a pull request May 3, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
database Content related to database. doc-enhancement Improve the current content [org][type][category] documentation Improvements or additions to documentation help wanted Good for community contributors to help [up-for-grabs] Pri1 High priority, do before Pri2 and Pri3 📌 seQUESTered Identifies that an issue has been imported into Quest.
Projects
Status: 🏗 In progress
Status: Slipped
Status: Slipped
Development

Successfully merging a pull request may close this issue.

6 participants