dotnet/efcore · error · InvalidOperationException

No relational database providers are configured. Configure…

Error message

No relational database providers are configured. Configure a database provider using 'OnConfiguring' or by creating an ImmutableDbContextOptions with a configured database provider and passing it to the context.

What it means

RelationalOptionsExtension.Extract inspects IDbContextOptions.Extensions for any RelationalOptionsExtension-derived entry (each UseSqlServer/UseNpgsql/UseSqlite call adds one). If none is present it throws NoProviderConfigured. Extract is called by relational services (migrations, raw SQL helpers, GetTableName, relational annotations) that cannot work without a relational provider.

Solutions

  1. Configure a relational provider in OnConfiguring or AddDbContext: optionsBuilder.UseSqlServer/UseNpgsql/UseSqlite(...).
  2. Do not call relational-specific APIs against the InMemory provider; guard the code path or switch tests to a relational provider (e.g. SQLite in-memory).
  3. If you build DbContextOptions manually, ensure exactly one relational extension is added.

Example fix

// before
optionsBuilder.UseInMemoryDatabase("test");
// later: context.Database.GetTableName(typeof(Customer)) -> [450]

// after — use a relational provider when relational APIs are needed
optionsBuilder.UseSqlite("DataSource=:memory:");
Defensive patterns

Strategy: validation

Validate before calling

// Confirm a relational provider extension is present before using relational APIs.
using Microsoft.EntityFrameworkCore;

static bool HasRelationalProvider(IDbContextOptions options)
    => options.Extensions.OfType<RelationalOptionsExtension>().Any();

Try / catch

try
{
    var table = context.Model.FindEntityType(typeof(Customer))!.GetTableName();
}
catch (InvalidOperationException ex) when (ex.Message.Contains("No relational database providers are configured"))
{
    // No relational provider configured; skip relational-only logic or configure one.
}

Prevention

When it happens

Trigger: Calling relational-only APIs on a context configured with the InMemory provider (or no provider at all): Database.GetTableName, Migrate, executing raw SQL via relational APIs, or accessing relational metadata annotations.

Common situations: Test fixture using UseInMemoryDatabase but production code calls a relational helper; forgetting OnConfiguring to call UseXxx; using a non-relational provider plugin.

Related errors


AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11). Data as JSON: /api/errors/3c8c43056c35e670. Report an issue: GitHub.

Appendix: source

Thrown at src/EFCore.Relational/Infrastructure/RelationalOptionsExtension.cs:422

        return clone;
    }

    /// <summary>
    ///     Finds an existing <see cref="RelationalOptionsExtension" /> registered on the given options
    ///     or throws if none has been registered. This is typically used to find some relational
    ///     configuration when it is known that a relational provider is being used.
    /// </summary>
    /// <param name="options">The context options to look in.</param>
    /// <returns>The extension.</returns>
    public static RelationalOptionsExtension Extract(IDbContextOptions options)
    {
        var relationalOptionsExtensions
            = options.Extensions
                .OfType<RelationalOptionsExtension>()
                .ToList();

        return relationalOptionsExtensions.Count == 0
            ? throw new InvalidOperationException(RelationalStrings.NoProviderConfigured)
            : relationalOptionsExtensions.Count > 1
                ? throw new InvalidOperationException(RelationalStrings.MultipleProvidersConfigured)
                : relationalOptionsExtensions[0];
    }

    /// <summary>
    ///     Adds the services required to make the selected options work. This is used when there
    ///     is no external <see cref="IServiceProvider" /> and EF is maintaining its own service
    ///     provider internally. This allows database providers (and other extensions) to register their
    ///     required services when EF is creating a service provider.
    /// </summary>
    /// <param name="services">The collection to add services to.</param>
    public abstract void ApplyServices(IServiceCollection services);

    /// <summary>
    ///     Gives the extension a chance to validate that all options in the extension are valid.
    ///     Most extensions do not have invalid combinations and so this will be a no-op.
    ///     If options are invalid, then an exception should be thrown.

View on GitHub (pinned to 3a2006ef56)