dotnet/efcore · error · InvalidOperationException

The 'EF.MultipleParameters<T>' method may only be used withi

Error message

The 'EF.MultipleParameters<T>' method may only be used within Entity Framework Core LINQ queries.

What it means

EF.MultipleParameters is a sentinel method whose body only ever throws — it exists solely to be recognized and rewritten by the EF LINQ translator. Executing it directly (outside a translated query) throws InvalidOperationException(RelationalStrings.EFMultipleParametersInvoked).

Source

Thrown at src/EFCore.Relational/EFExtensions.cs:35

    /// <summary>
    ///     Methods that are useful in application code. For example, referencing a shadow state property in a LINQ query.
    /// </summary>
    /// <remarks>
    ///     See <see href="https://aka.ms/efcore-docs-database-functions">Database functions</see> and
    ///     <see href="https://aka.ms/efcore-docs-efproperty">Using EF.Property in EF Core queries</see> for more information and examples.
    /// </remarks>
    extension(EF)
    {
        /// <summary>
        ///     Within the context of an EF LINQ query, forces its argument to be inserted into the query as a multiple parameter expressions.
        /// </summary>
        /// <remarks>Note that this is a static method accessed through the top-level <see cref="EF" /> static type.</remarks>
        /// <typeparam name="TSource">The type of collection.</typeparam>
        /// <param name="argument">The collection to be integrated as parameters into the query.</param>
        /// <returns>The same value for further use in the query.</returns>
        public static TSource MultipleParameters<TSource>(TSource argument)
            where TSource : IEnumerable
            => throw new InvalidOperationException(RelationalStrings.EFMultipleParametersInvoked);
    }
}

View on GitHub (pinned to dbf9771522)

Solutions

  1. Ensure EF.MultipleParameters is used inside a query that EF translates to SQL — keep it before any AsEnumerable()/ToList() boundary.
  2. Rewrite the query so the argument is translatable (avoid wrapping in un-translatable client methods).
  3. If client evaluation is unavoidable, expand the collection manually into the query instead of using the sentinel.
  4. Verify your database provider supports multi-parameter expansion for that query shape.

Example fix

// before
var ids = GetIds();
var expanded = EF.MultipleParameters(ids); // throws on client
var q = ctx.Users.Where(u => expanded.Contains(u.Id));

// after (use inside the translated query only)
var q = ctx.Users.Where(u => EF.MultipleParameters(ids).Contains(u.Id));
Defensive patterns

Strategy: validation

Validate before calling

// MultipleParameters must be inside a translated query; verify usage stays server-side
// (static guard: do not call outside IQueryable expression trees)
public static T MultiParamInQuery<T>(IQueryable<T> q, IEnumerable arg)
    => q.Where(/* uses EF.MultipleParameters(arg) */).First();
// Never invoke the EF.MultipleParameters value directly.

Prevention

When it happens

Trigger: Calling EF.MultipleParameters(collection) in client-side code, or in a LINQ expression that EF fails to translate and therefore evaluates on the client (EFExtensions.cs:33-35). The method must appear inside a query EF translates so the provider can expand the collection into multiple SQL parameters.

Common situations: Using EF.MultipleParameters inside a query that falls back to client evaluation (e.g. wrapped in an un-translatable method); invoking it eagerly on a materialized list; mixing with AsEnumerable before the call; provider that doesn't support multi-parameter expansion.

Related errors


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