Мы уже давно используем EF 5 в нескольких приложениях, но у нас никогда не было времени обновлять, также из -за зависимостей. < /p>
Но теперь у нас есть Обновлено, что почти не было обновлений, необходимого необходимого кода. Локальный (в Visual Studio) нет никаких проблем. Но после развертывания мы столкнулись с проблемой. Сначала не возникает проблем, веб -сайт работает и работает, мы можем получить доступ к базе данных. Br />
2025-02-17 13:56:56.799 +01:00 [ERR](Correlation-ID: 40000484-0000-c600-b63f-84710c7967bb) Internal server error. Routeinfo: v{version:apiVersion}/Dashboard/errors.
System.InvalidOperationException: No database provider has been configured for this DbContext. A provider can be configured by overriding the 'DbContext.OnConfiguring' method or by using 'AddDbContext' on the application service provider. If 'AddDbContext' is used, then also ensure that your DbContext type accepts a DbContextOptions object in its constructor and passes it to the base constructor for DbContext.
at Microsoft.EntityFrameworkCore.Internal.DbContextServices.Initialize(IServiceProvider scopedProvider, DbContextOptions contextOptions, DbContext context)
at Microsoft.EntityFrameworkCore.DbContext.get_ContextServices()
at Microsoft.EntityFrameworkCore.DbContext.get_Model()
at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.get_EntityType()
at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.CheckState()
at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.get_EntityQueryable()
at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.System.Collections.Generic.IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken)
at System.Runtime.CompilerServices.ConfiguredCancelableAsyncEnumerable`1.GetAsyncEnumerator()
at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
at Beheer.Services.Dashboard.DashboardService.GetMaxDaysFromSettings() in D:\Agents\Agent.Morpheus\_work\2\s\Back-end\Beheer.Services\Dashboard\DashboardService.cs:line 330
at Beheer.Services.Dashboard.DashboardService.GetRecentErrorLogs(Paging paging) in D:\Agents\Agent.Morpheus\_work\2\s\Back-end\Beheer.Services\Dashboard\DashboardService.cs:line 137
at Beheer.Api.Controllers.DashboardController.GetRecentErrorLogs(Paging paging) in D:\Agents\Agent.Morpheus\_work\2\s\Back-end\Beheer.Api\Controllers\DashboardController.cs:line 99
at lambda_method62(Closure, Object)
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
< /code>
Соответствующий код: < /p>
public static class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
private static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext, config) =>
{
var env = hostingContext.HostingEnvironment.EnvironmentName;
config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
config.AddJsonFile($"appsettings.{env}.json", optional: true, reloadOnChange: true);
config.AddEnvironmentVariables();
if (args != null)
{
config.AddCommandLine(args);
}
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup();
})
.UseSerilog((hostingContext, loggerConfiguration) => loggerConfiguration
.ReadFrom.AppSettings().Enrich.FromLogContext());
}
< /code>
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
var connectionString = Configuration["AppSettings:ConnectionString"];
services.AddDbContext(options => options.UseOracle(connectionString));
....
}
}
< /code>
public class MyContext : DbContext
{
public MyContext()
{
}
public MyContext(DbContextOptions options)
: base(options)
{
}
public virtual DbSet SenderSettings { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
}
}
Некоторое руководство, что делать дальше, будет оценено.
Мы уже давно используем EF 5 в нескольких приложениях, но у нас никогда не было времени обновлять, также из -за зависимостей. < /p> Но теперь у нас есть Обновлено, что почти не было обновлений, необходимого необходимого кода. Локальный (в Visual Studio) нет никаких проблем. Но после развертывания мы столкнулись с проблемой. Сначала не возникает проблем, веб -сайт работает и работает, мы можем получить доступ к базе данных. Br />[code]2025-02-17 13:56:56.799 +01:00 [ERR](Correlation-ID: 40000484-0000-c600-b63f-84710c7967bb) Internal server error. Routeinfo: v{version:apiVersion}/Dashboard/errors. System.InvalidOperationException: No database provider has been configured for this DbContext. A provider can be configured by overriding the 'DbContext.OnConfiguring' method or by using 'AddDbContext' on the application service provider. If 'AddDbContext' is used, then also ensure that your DbContext type accepts a DbContextOptions object in its constructor and passes it to the base constructor for DbContext. at Microsoft.EntityFrameworkCore.Internal.DbContextServices.Initialize(IServiceProvider scopedProvider, DbContextOptions contextOptions, DbContext context) at Microsoft.EntityFrameworkCore.DbContext.get_ContextServices() at Microsoft.EntityFrameworkCore.DbContext.get_Model() at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.get_EntityType() at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.CheckState() at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.get_EntityQueryable() at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.System.Collections.Generic.IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) at System.Runtime.CompilerServices.ConfiguredCancelableAsyncEnumerable`1.GetAsyncEnumerator() at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken) at Beheer.Services.Dashboard.DashboardService.GetMaxDaysFromSettings() in D:\Agents\Agent.Morpheus\_work\2\s\Back-end\Beheer.Services\Dashboard\DashboardService.cs:line 330 at Beheer.Services.Dashboard.DashboardService.GetRecentErrorLogs(Paging paging) in D:\Agents\Agent.Morpheus\_work\2\s\Back-end\Beheer.Services\Dashboard\DashboardService.cs:line 137 at Beheer.Api.Controllers.DashboardController.GetRecentErrorLogs(Paging paging) in D:\Agents\Agent.Morpheus\_work\2\s\Back-end\Beheer.Api\Controllers\DashboardController.cs:line 99 at lambda_method62(Closure, Object) at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) < /code> Соответствующий код: < /p> public static class Program { public static void Main(string[] args) { CreateHostBuilder(args).Build().Run(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var connectionString = Configuration["AppSettings:ConnectionString"]; services.AddDbContext(options => options.UseOracle(connectionString));
.... } } < /code> public class MyContext : DbContext { public MyContext() { }
public MyContext(DbContextOptions options) : base(options) { }