dotnet/efcore · error · ArgumentException
The DbFunction ' ' does not have a parameter named ' '.
Error message
The DbFunction '{function}' does not have a parameter named '{parameter}'. What it means
HasParameter(name) on a DbFunction builder returns the parameter builder only if a parameter with that exact name exists. The method throws an ArgumentException when Metadata.FindParameter(name) returns null — i.e. the declared method has no parameter with that name (typo, renamed parameter, or wrong overload).
Solutions
- Open the method registered as the DbFunction and copy the exact parameter name (case-sensitive).
- Update the .HasParameter(...) call to match the current parameter name.
- If the parameter was intentionally removed, drop the HasParameter configuration block for it.
Example fix
// before
public IQueryable<Order> Search(string term) => throw new NotSupportedException();
modelBuilder.HasDbFunction(typeof(AppDb).GetMethod(nameof(Search)))
.HasParameter("searchTerm"); // wrong name
// after
modelBuilder.HasDbFunction(typeof(AppDb).GetMethod(nameof(Search)))
.HasParameter("term"); Defensive patterns
Strategy: validation
Validate before calling
var fnBuilder = modelBuilder.HasDbFunction(typeof(AppDb).GetMethod(nameof(AppDb.Search))!);
const string paramName = "term";
if (fnBuilder.Metadata.FindParameter(paramName) is null)
{
throw new InvalidOperationException($"DbFunction has no parameter '{paramName}'.");
}
fnBuilder.HasParameter(paramName); Type guard
static bool DbFunctionHasParameter(IReadOnlyDbFunction fn, string name)
=> fn.FindParameter(name) is not null; Prevention
- Use nameof() on the method's parameter where possible so renames stay in sync.
- After refactoring a method's parameters, grep for HasParameter calls referencing it.
When it happens
Trigger: Calling .HasParameter("searchTerm") when the underlying method's parameter is named "term"; using the parameter name from a different overload; refactor that renamed a method parameter without updating the DbFunction configuration.
Common situations: Renaming a method parameter via IDE refactor that does not touch OnModelCreating; copy-pasted configuration referencing another function's parameters; signature mismatch after a refactor.
Related errors
- 'PropagatesNullability' cannot be set on parameter
- The DbFunction ' ' defined on type ' ' must be either a…
- The DbFunction ' ' has an invalid return type ' '. Ensure…
- The DbFunction ' ' has an invalid return type ' '…
- The DbFunction ' ' is generic. Mapping generic methods as a…
AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11).
Data as JSON: /api/errors/3d016b27cca6ea26.
Report an issue: GitHub.
Appendix: source
Thrown at src/EFCore.Relational/Metadata/Internal/InternalDbFunctionBuilder.cs:235
/// </summary>
public virtual bool CanSetTranslation(
Func<IReadOnlyList<SqlExpression>, SqlExpression>? translation,
ConfigurationSource configurationSource)
=> (Metadata is { IsScalar: true, IsAggregate: false } || configurationSource == ConfigurationSource.Explicit)
&& (configurationSource.Overrides(Metadata.GetTranslationConfigurationSource())
|| Metadata.Translation == translation);
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual InternalDbFunctionParameterBuilder HasParameter(string name, ConfigurationSource configurationSource)
{
var parameter = Metadata.FindParameter(name);
return parameter == null
? throw new ArgumentException(
RelationalStrings.DbFunctionInvalidParameterName(Metadata.MethodInfo?.DisplayName(), name))
: parameter.Builder;
}
IConventionDbFunction IConventionDbFunctionBuilder.Metadata
{
[DebuggerStepThrough]
get => Metadata;
}
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
[DebuggerStepThrough]
IConventionDbFunctionBuilder? IConventionDbFunctionBuilder.HasAnnotation(string name, object? value, bool fromDataAnnotation)View on GitHub (pinned to 3a2006ef56)