{"record":{"id":"b64c552781c0ec44","repo":"dotnet/efcore","slug":"the-ef-multipleparameters-t-method-may-only-be","errorCode":null,"errorMessage":"The 'EF.MultipleParameters<T>' method may only be used within Entity Framework LINQ queries.","messagePattern":"The 'EF\\.MultipleParameters<T>' method may only be used within Entity Framework LINQ queries\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/EFExtensions.cs","lineNumber":35,"sourceCode":"    /// <summary>\n    ///     Methods that are useful in application code. For example, referencing a shadow state property in a LINQ query.\n    /// </summary>\n    /// <remarks>\n    ///     See <see href=\"https://aka.ms/efcore-docs-database-functions\">Database functions</see> and\n    ///     <see href=\"https://aka.ms/efcore-docs-efproperty\">Using EF.Property in EF Core queries</see> for more information and examples.\n    /// </remarks>\n    extension(EF)\n    {\n        /// <summary>\n        ///     Within the context of an EF LINQ query, forces its argument to be inserted into the query as a multiple parameter expressions.\n        /// </summary>\n        /// <remarks>Note that this is a static method accessed through the top-level <see cref=\"EF\" /> static type.</remarks>\n        /// <typeparam name=\"TSource\">The type of collection.</typeparam>\n        /// <param name=\"argument\">The collection to be integrated as parameters into the query.</param>\n        /// <returns>The same value for further use in the query.</returns>\n        public static TSource MultipleParameters<TSource>(TSource argument)\n            where TSource : IEnumerable\n            => throw new InvalidOperationException(RelationalStrings.EFMultipleParametersInvoked);\n    }\n}\n","sourceCodeStart":17,"sourceCodeEnd":38,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/EFExtensions.cs#L17-L38","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before: evaluated client-side because source is a List\nvar list = new List<Order>();\nvar q = list.Where(o => EF.MultipleParameters(ids).Contains(o.Id)); // throws\n\n// after: query against the DbContext so it translates\nvar q = context.Orders\n    .Where(o => EF.MultipleParameters(ids).Contains(o.Id));","handlingStrategy":"validation","validationCode":"// Only use EF.MultipleParameters within an EF-translated query\nIQueryable<Order> q = context.Orders;\nif (q is IQueryable) // ensure provider-backed queryable\n{\n    var result = q.Where(o => EF.MultipleParameters(ids).Contains(o.Id)).ToList();\n}\nelse\n{\n    // client-side fallback: expand manually\n    var result = q.Where(o => ids.Contains(o.Id)).ToList();\n}","typeGuard":"static bool IsProviderQuery<T>(IQueryable<T> q)\n    => q.Provider.GetType().FullName?.Contains(\"EntityFrameworkCore\", StringComparison.OrdinalIgnoreCase) == true;","tryCatchPattern":null,"preventionTips":["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."],"tags":["ef-core","linq","query-translation","relational","client-evaluation"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}