dotnet/efcore · error · ArgumentException

The DbFunction '{function}' does not have a parameter named

Error message

The DbFunction '{function}' does not have a parameter named '{parameter}'.

What it means

Thrown by InternalDbFunctionBuilder.HasParameter when Metadata.FindParameter(name) returns null — i.e. no parameter with the requested name exists on the DbFunction. The builder cannot return a parameter builder for a parameter that was never declared.

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 dbf9771522)

Solutions

  1. Correct the parameter name to exactly match a parameter of the mapped method (case-sensitive).
  2. If you used the string-based DbFunction constructor, ensure parameters were supplied via the parameters argument.
  3. Use nameof(...) on the method parameter instead of a string literal to avoid typos.
  4. List the function's parameters (FindParameter / Parameters) to confirm available names before configuring.

Example fix

// before
public decimal TaxFor(decimal amount, string region) => 0m;
modelBuilder.HasDbFunction(typeof(Ctx).GetMethod("TaxFor"))
    .HasParameter("amt").HasPropagatesNullability(false); // wrong name

// after
modelBuilder.HasDbFunction(typeof(Ctx).GetMethod("TaxFor"))
    .HasParameter(nameof(TaxFor) /* not valid */ );
// better: derive from the method
modelBuilder.HasDbFunction(typeof(Ctx).GetMethod("TaxFor"))
    .HasParameter("amount").HasPropagatesNullability(false);
Defensive patterns

Strategy: validation

Validate before calling

// Verify the parameter exists before configuring
var param = fn.FindParameter(name);
if (param is null)
    throw new InvalidOperationException($"No parameter '{name}' on {fn.ModelName}.");
param.Builder.HasPropagatesNullability(false);

Prevention

When it happens

Trigger: Calling .HasParameter("someName") where 'someName' does not match any parameter of the underlying method (typo, wrong casing, or a renamed parameter). Also when configuring a DbFunction built via the string overload with no parameters declared.

Common situations: Parameter renamed in the method signature but the fluent config still uses the old name. Mismatch between the case/spacing of the parameter name and the string passed to HasParameter.

Related errors


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