✅ How to automate update-database
I am bilding a Web server but i have to typ in update-database how can i automate this in Blazor in the Program.cs file.
Im srry i cant be more specific because im new in this kind of stuff.
The tutorial i watch is just outdated the code changed a bit.
Tanks for your time and helping.
In the tutorial https://www.youtube.com/watch?v=JeLnR_ObHd8&t=4624s on 1:16:57 - 1:17:17
and i have the most recent Version of Microsoft Visual Studio if u also have it and it looks like that:
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseMigrationsEndPoint();
}
else
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
Coding mit Jannick
YouTube
Erstelle und hoste eine Blazor Server App mit ASP.NET Core, VS 2022...
In diesem Video erstellst du deine erste Blazor Server App vom Scratch bis hin zur Veröffentlichung im IIS auf einem Windows Server.
🔥 Hier geht's zum Contabo Windows Server Angebot:
https://bit.ly/3IOlzOT
SQL Server Express 2019:
https://www.microsoft.com/de-DE/download/details.aspx?id=101064
ASP.NET Core 5.0 Hosting Bundle (erst SQL Server ...
17 Replies
if you get an instance of your dbcontext you can call
dbContext.Database.Migrate()
i wanna updat sql datenbanken
databanks
the method i suggested does the same thing as update-database
if u know where i have to put it because as u wrote i cant put it in the Program.cs file
how can i put code in this extra blackish window on discord
$codegif
this is how the program.cs looks like
should be roughly that, i typed it in discord so no compiler checking
you need a service scope because
.AddDbContext
registers the dbcontext as a scoped service
an alternative is .AddDbContextFactory
and using IDbContextFactory<ApplicationDbContext>
"IServiceScope" has no definition for "GetRequiredService", and the overload of the optimal extension method "ServiceProviderServiceExtensions.GetRequiredService<ApplicationDbContext>(IServiceProvider)" needs a receiver of the typ "System.IServiceProvider".
corrected
what now
use the updated code
i edited the message
oh thank u it now at least works. I dont know if it does what I want but 🫨 . I hope I didn´t distract u with my silly question.
it does do what you want
you want to do
update-database
but in code right?
this will apply migrations automatically when your app startsje so when i take it online it does it automaticly
$close
Use the /close command to mark a forum thread as answered