{"record":{"id":"ac701f7f849ab274","repo":"dotnet/efcore","slug":"metadata-model-returned-should-not-be-null-prov","errorCode":null,"errorMessage":"Metadata model returned should not be 'null'. Provider: {providerTypeName}.","messagePattern":"Metadata model returned should not be 'null'\\. Provider: (.+?)\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Scaffolding/Internal/ReverseEngineerScaffolder.cs","lineNumber":103,"sourceCode":"        }\n        else if (!codeOptions.SuppressOnConfiguring)\n        {\n            _reporter.WriteWarning(DesignStrings.SensitiveInformationWarning);\n        }\n\n        codeOptions.ConnectionString ??= connectionString;\n\n        var databaseModel = _databaseModelFactory.Create(resolvedConnectionString, databaseOptions);\n        var modelConnectionString = (string?)databaseModel[ScaffoldingAnnotationNames.ConnectionString];\n        if (!string.IsNullOrEmpty(modelConnectionString))\n        {\n            codeOptions.ConnectionString = modelConnectionString;\n        }\n\n        var model = _factory.Create(databaseModel, modelOptions);\n        if (model == null)\n        {\n            throw new InvalidOperationException(\n                DesignStrings.ProviderReturnedNullModel(\n                    _factory.GetType().ShortDisplayName()));\n        }\n\n        if (string.IsNullOrEmpty(codeOptions.ContextName))\n        {\n            var annotatedName = model.GetDatabaseName();\n            codeOptions.ContextName = !string.IsNullOrEmpty(annotatedName)\n                ? _code.Identifier(annotatedName + DbContextSuffix)\n                : DefaultDbContextName;\n        }\n\n        var codeGenerator = ModelCodeGeneratorSelector.Select(codeOptions);\n\n        return codeGenerator.GenerateModel(model, codeOptions);\n    }\n\n    /// <summary>","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Design/Scaffolding/Internal/ReverseEngineerScaffolder.cs#L85-L121","documentation":"Thrown after the database provider's IScaffoldingModelFactory.Create() returns null when converting the reverse-engineered DatabaseModel into an EF IModel. EF Core requires a non-null model from the provider; a null return signals an internal provider defect, not a user modeling problem. The message names the offending factory type to localize the bug.","triggerScenarios":"Calling ScaffoldModel/Scaffold (or `dotnet ef dbcontext scaffold`) against a provider whose IScaffoldingModelFactory implementation returns null from Create(databaseModel, modelOptions). Reached once the database schema has been read successfully and the model-building step begins.","commonSituations":"A third-party or custom EF Core provider whose scaffolding adapter is incomplete or mismatched to the installed EFCore.Design version. Rarely, a provider version regression after upgrading EFCore.Design while the database provider package lags behind.","solutions":["Update the database provider package (e.g. Microsoft.EntityFrameworkCore.SqlServer, Pomelo, Npgsql) to the version matching your EFCore.Design/EFCore version.","If using a custom or preview provider, inspect its IScaffoldingModelFactory implementation for a code path that returns null.","Open an issue with the provider project, including the factory type name from the message and the database schema that triggered it.","As a workaround, scaffold against SQL Server/SQLite/localdb to validate the rest of the pipeline, then swap providers."],"exampleFix":"// before: mismatched versions\n//   EFCore.Design 8.0.x  +  provider 7.0.x\n// after: align patch versions\n//   dotnet add package Microsoft.EntityFrameworkCore.SqlServer --version 8.0.x\n//   dotnet add package Microsoft.EntityFrameworkCore.Design --version 8.0.x","handlingStrategy":"validation","validationCode":"// Before scaffolding, confirm provider + design versions match\nvar designVer = typeof(DesignStrings).Assembly.GetName().Version;\nvar providerVer = providerAssembly.GetName().Version;\nif (designVer.Major != providerVer.Major)\n{\n    throw new InvalidOperationException($\"Provider {providerVer} mismatches EFCore.Design {designVer}\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep EFCore.Design and every provider package on the same major+minor release.","Run scaffold against a known-good provider first to validate the pipeline.","Pin provider versions in Directory.Packages.props to avoid transitive drift."],"tags":["scaffolding","reverse-engineering","provider","design-time"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}