How to set command timeout in ASP.NET Core / Entity Framework Core?

asp.net-core, c#, entity-framework-core

Solution

If you're using the DI container to manage the DbContext (i.e. you're adding the DbContext to the service collection), the command timeout can be specified in the options.

In Startup.ConfigureServices:

services.AddDbContext<YourDbContext>(options => options.UseSqlServer(
    this.Configuration.GetConnectionString("YourConnectionString"),
    sqlServerOptions => sqlServerOptions.CommandTimeout(60))
);

Problem

The place where the command timeout is set is no longer the same as earlier versions. However, I cannot find anywhere that says how to change this. What I am doing is uploading very large files which takes longer than the default 30 seconds to save. Note that I ask about command timeout, not migration timeout as in another question.

Original source

Related problems