dotnet/efcore · error · InvalidOperationException
The 'EF.MultipleParameters
Error message
The 'EF.MultipleParameters<T>' method may only be used within Entity Framework LINQ queries.
What it means
EF.MultipleParameters is an intentional query-only marker: inside an EF LINQ query the provider rewrites it to inline the collection as a parameter list; the method body unconditionally throws so that any direct (client-side) invocation fails loudly. Hitting it means the call was not translated and instead executed in-process.
Solutions
- Ensure EF.MultipleParameters is used only inside a query that the EF provider translates (start from context.Set<T>().Where(...) not a List<T>).
- If client-side expansion is what you want, expand the collection yourself (e.g. .Where(e => ids.Contains(e.Id))) instead of using the marker.
- Upgrade the EF Core provider to a version that supports MultipleParameters translation.
Example fix
// before: evaluated client-side because source is a List
var list = new List<Order>();
var q = list.Where(o => EF.MultipleParameters(ids).Contains(o.Id)); // throws
// after: query against the DbContext so it translates
var q = context.Orders
.Where(o => EF.MultipleParameters(ids).Contains(o.Id)); Defensive patterns
Strategy: validation
Validate before calling
// Only use EF.MultipleParameters within an EF-translated query
IQueryable<Order> q = context.Orders;
if (q is IQueryable) // ensure provider-backed queryable
{
var result = q.Where(o => EF.MultipleParameters(ids).Contains(o.Id)).ToList();
}
else
{
// client-side fallback: expand manually
var result = q.Where(o => ids.Contains(o.Id)).ToList();
} Type guard
static bool IsProviderQuery<T>(IQueryable<T> q)
=> q.Provider.GetType().FullName?.Contains("EntityFrameworkCore", StringComparison.OrdinalIgnoreCase) == true; Prevention
- Always start queries from the DbContext (context.Set<T>()) so the provider translates.
- Avoid calling EF query-only helpers from helper methods that receive IEnumerable.
- Prefer ids.Contains(...) for client-computed collections.
When it happens
Trigger: Calling EF.MultipleParameters(collection) outside of an EF query, or in a context where the provider failed to translate it (e.g. on an in-memory/IEnumerable sequence rather than an IQueryable against the DbContext).
Common situations: Mixing LINQ-to-Objects and EF queries so the EF provider no longer sees the call; invoking the helper from a unit test or helper method against an in-memory list; provider version that does not support MultipleParameters translation.
Related errors
- The ' ' method is not supported because the query has…
- The LINQ expression ' ' could not be translated. Either…
- The LINQ expression ' ' could not be translated. Additional…
- Async lambdas are not supported
- Could not find type symbol for
AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11).
Data as JSON: /api/errors/b64c552781c0ec44.
Report an issue: GitHub.
Appendix: 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 3a2006ef56)