Небольшие фиксы
This commit is contained in:
parent
34eaf01df0
commit
a3f26ec9f2
@ -26,35 +26,7 @@ public static class DbHelpersEndpointsExtensions
|
||||
await dbContext.Database.MigrateAsync();
|
||||
return Results.Ok();
|
||||
});
|
||||
|
||||
group.MapPost("/initdb/{contexClassName}", async (string contexClasstName, IServiceProvider services) =>
|
||||
{
|
||||
var contextType = GetEfCoreClassContexts().FirstOrDefault(c => c.Name == contexClasstName);
|
||||
|
||||
if(contextType is null)
|
||||
return Results.NotFound();
|
||||
|
||||
using var scope = services.CreateScope();
|
||||
|
||||
var dbContext = (DbContext)scope.ServiceProvider.GetRequiredService(contextType);
|
||||
|
||||
await dbContext.Database.EnsureCreatedAsync();
|
||||
return Results.Ok();
|
||||
});
|
||||
|
||||
group.MapPost("/initdb", async (IServiceProvider services) =>
|
||||
{
|
||||
foreach(var contextType in GetEfCoreClassContexts())
|
||||
{
|
||||
using var scope = services.CreateScope();
|
||||
|
||||
var dbContext = (DbContext)scope.ServiceProvider.GetRequiredService(contextType);
|
||||
|
||||
await dbContext.Database.EnsureCreatedAsync();
|
||||
}
|
||||
return Results.Ok();
|
||||
});
|
||||
|
||||
|
||||
group.MapPost("/migrate", async (IServiceProvider services) =>
|
||||
{
|
||||
foreach(var contextType in GetEfCoreClassContexts())
|
||||
|
@ -21,7 +21,7 @@ public static class ReflectionHelpers
|
||||
//Get all types with DbContext parent type
|
||||
EfCoreDbContexts = typeof(Program).Assembly.GetTypes().Where(t =>
|
||||
t.GetInheritanceChain().Any(inheritanType =>
|
||||
inheritanType.Name is not null && inheritanType.Name == nameof(DbContext)));
|
||||
!string.IsNullOrEmpty(inheritanType.Name) && inheritanType.Name == nameof(DbContext)));
|
||||
}
|
||||
return EfCoreDbContexts;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user