Небольшие фиксы
This commit is contained in:
		| @@ -27,34 +27,6 @@ public static class DbHelpersEndpointsExtensions | |||||||
|             return Results.Ok(); |             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) =>  |         group.MapPost("/migrate", async (IServiceProvider services) =>  | ||||||
|         { |         { | ||||||
|             foreach(var contextType in GetEfCoreClassContexts()) |             foreach(var contextType in GetEfCoreClassContexts()) | ||||||
|   | |||||||
| @@ -21,7 +21,7 @@ public static class ReflectionHelpers | |||||||
|             //Get all types with DbContext parent type |             //Get all types with DbContext parent type | ||||||
|             EfCoreDbContexts = typeof(Program).Assembly.GetTypes().Where(t =>  |             EfCoreDbContexts = typeof(Program).Assembly.GetTypes().Where(t =>  | ||||||
|                 t.GetInheritanceChain().Any(inheritanType =>  |                 t.GetInheritanceChain().Any(inheritanType =>  | ||||||
|                     inheritanType.Name is not null && inheritanType.Name == nameof(DbContext))); |                     !string.IsNullOrEmpty(inheritanType.Name) && inheritanType.Name == nameof(DbContext))); | ||||||
|         } |         } | ||||||
|         return EfCoreDbContexts; |         return EfCoreDbContexts; | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user