{"record":{"id":"f0e54553e5fe2261","repo":"dotnet/efcore","slug":"the-parameter-parameter-for-the-dbfunction-f","errorCode":null,"errorMessage":"The parameter '{parameter}' for the DbFunction '{function}' has an invalid type '{type}'. Ensure the parameter type can be mapped by the current provider.","messagePattern":"The parameter '(.+?)' for the DbFunction '(.+?)' has an invalid type '(.+?)'\\. Ensure the parameter type can be mapped by the current provider\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs","lineNumber":406,"sourceCode":"            {\n                throw new InvalidOperationException(\n                    RelationalStrings.DbFunctionInvalidReturnEntityType(\n                        dbFunction.ModelName, dbFunction.ReturnType.ShortDisplayName(), elementType.ShortDisplayName()));\n            }\n\n            if ((entityType.BaseType != null || entityType.GetDerivedTypes().Any())\n                && entityType.FindDiscriminatorProperty() == null)\n            {\n                throw new InvalidOperationException(\n                    RelationalStrings.TableValuedFunctionNonTph(dbFunction.ModelName, entityType.DisplayName()));\n            }\n        }\n\n        foreach (var parameter in dbFunction.Parameters)\n        {\n            if (parameter.TypeMapping == null)\n            {\n                throw new InvalidOperationException(\n                    RelationalStrings.DbFunctionInvalidParameterType(\n                        parameter.Name,\n                        dbFunction.ModelName,\n                        parameter.ClrType.ShortDisplayName()));\n            }\n        }\n    }\n\n    /// <summary>\n    ///     Validates the function mapping for an entity type.\n    /// </summary>\n    /// <param name=\"entityType\">The entity type to validate.</param>\n    /// <param name=\"logger\">The logger to use.</param>\n    protected virtual void ValidateDbFunctionMapping(\n        IEntityType entityType,\n        IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)\n    {\n        var mappedFunctionName = entityType.GetFunctionName();","sourceCodeStart":388,"sourceCodeEnd":424,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs#L388-L424","documentation":"ValidateDbFunction (RelationalModelValidator.cs:402-412) throws when any parameter of a DbFunction has a null TypeMapping - i.e. the current provider cannot map that parameter's CLR type to a SQL parameter type. A DbFunction call must translate every argument to a provider parameter; an unmappable parameter type breaks translation, so the function registration is rejected at validation.","triggerScenarios":"Registering a DbFunction with a parameter whose CLR type the provider does not map (custom struct/enum without conversion, or an unsupported primitive like char/decimal-precision edge cases on some providers). Thrown at model validation.","commonSituations":"Enum parameters without HasConversion; custom value-type parameters; provider-specific gaps (e.g. certain spatial/time types); porting DbFunctions between providers with narrower type coverage.","solutions":["Change the parameter type to a primitive the provider maps (int, string, DateTime, etc.).","For enum/custom types, apply a value converter (HasConversion) so the parameter maps to a supported primitive.","If the type is legitimately needed, add a provider-specific type mapping plugin."],"exampleFix":"// before\npublic List<Post> PostsByStatus(PostStatus status) => null!; // PostStatus enum unmapped\nmodelBuilder.HasDbFunction(() => PostsByStatus(default)); // throws: parameter type unmapped\n\n// after - map enum to int\nmodelBuilder.HasDbFunction(() => PostsByStatus(default));\n// ensure the enum is converted:\nmodelBuilder.Entity<Post>().Property(p => p.Status).HasConversion<int>();\n// or change the DbFunction signature to take int directly:\n// public List<Post> PostsByStatus(int status) => null!;","handlingStrategy":"validation","validationCode":"foreach (var fn in context.Model.GetDbFunctions())\n{\n    foreach (var param in fn.Parameters)\n    {\n        if (param.TypeMapping == null)\n        {\n            // will throw - use a mapped primitive or add a value converter for this param type.\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use provider-mappable primitive parameter types for DbFunctions.","Add HasConversion for enum/custom parameter types.","Validate all DbFunction parameters against the provider's type map at build time."],"tags":["dbfunction","type-mapping","parameter","enum","model-validation"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}