{"record":{"id":"3c8c43056c35e670","repo":"dotnet/efcore","slug":"no-relational-database-providers-are-configured-c","errorCode":null,"errorMessage":"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.","messagePattern":"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\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Infrastructure/RelationalOptionsExtension.cs","lineNumber":422,"sourceCode":"        return clone;\n    }\n\n    /// <summary>\n    ///     Finds an existing <see cref=\"RelationalOptionsExtension\" /> registered on the given options\n    ///     or throws if none has been registered. This is typically used to find some relational\n    ///     configuration when it is known that a relational provider is being used.\n    /// </summary>\n    /// <param name=\"options\">The context options to look in.</param>\n    /// <returns>The extension.</returns>\n    public static RelationalOptionsExtension Extract(IDbContextOptions options)\n    {\n        var relationalOptionsExtensions\n            = options.Extensions\n                .OfType<RelationalOptionsExtension>()\n                .ToList();\n\n        return relationalOptionsExtensions.Count == 0\n            ? throw new InvalidOperationException(RelationalStrings.NoProviderConfigured)\n            : relationalOptionsExtensions.Count > 1\n                ? throw new InvalidOperationException(RelationalStrings.MultipleProvidersConfigured)\n                : relationalOptionsExtensions[0];\n    }\n\n    /// <summary>\n    ///     Adds the services required to make the selected options work. This is used when there\n    ///     is no external <see cref=\"IServiceProvider\" /> and EF is maintaining its own service\n    ///     provider internally. This allows database providers (and other extensions) to register their\n    ///     required services when EF is creating a service provider.\n    /// </summary>\n    /// <param name=\"services\">The collection to add services to.</param>\n    public abstract void ApplyServices(IServiceCollection services);\n\n    /// <summary>\n    ///     Gives the extension a chance to validate that all options in the extension are valid.\n    ///     Most extensions do not have invalid combinations and so this will be a no-op.\n    ///     If options are invalid, then an exception should be thrown.","sourceCodeStart":404,"sourceCodeEnd":440,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Infrastructure/RelationalOptionsExtension.cs#L404-L440","documentation":"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.","triggerScenarios":"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.","commonSituations":"Test fixture using UseInMemoryDatabase but production code calls a relational helper; forgetting OnConfiguring to call UseXxx; using a non-relational provider plugin.","solutions":["Configure a relational provider in OnConfiguring or AddDbContext: optionsBuilder.UseSqlServer/UseNpgsql/UseSqlite(...).","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).","If you build DbContextOptions manually, ensure exactly one relational extension is added."],"exampleFix":"// before\noptionsBuilder.UseInMemoryDatabase(\"test\");\n// later: context.Database.GetTableName(typeof(Customer)) -> [450]\n\n// after — use a relational provider when relational APIs are needed\noptionsBuilder.UseSqlite(\"DataSource=:memory:\");","handlingStrategy":"validation","validationCode":"// Confirm a relational provider extension is present before using relational APIs.\nusing Microsoft.EntityFrameworkCore;\n\nstatic bool HasRelationalProvider(IDbContextOptions options)\n    => options.Extensions.OfType<RelationalOptionsExtension>().Any();","typeGuard":null,"tryCatchPattern":"try\n{\n    var table = context.Model.FindEntityType(typeof(Customer))!.GetTableName();\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"No relational database providers are configured\"))\n{\n    // No relational provider configured; skip relational-only logic or configure one.\n}","preventionTips":["Always configure a relational provider (UseXxx) in OnConfiguring / AddDbContext when relational APIs are used.","Do not call relational helpers (GetTableName, Migrate, raw SQL) against UseInMemoryDatabase.","Guard relational code paths with a provider check in shared test/prod code."],"tags":["configuration","provider","relational"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}