{"record":{"id":"61494f1e375e4c69","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 Core LINQ queries.","messagePattern":"The 'EF\\.MultipleParameters<T>' method may only be used within Entity Framework Core 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/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/EFExtensions.cs#L17-L38","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure EF.MultipleParameters is used inside a query that EF translates to SQL — keep it before any AsEnumerable()/ToList() boundary.","Rewrite the query so the argument is translatable (avoid wrapping in un-translatable client methods).","If client evaluation is unavoidable, expand the collection manually into the query instead of using the sentinel.","Verify your database provider supports multi-parameter expansion for that query shape."],"exampleFix":"// before\nvar ids = GetIds();\nvar expanded = EF.MultipleParameters(ids); // throws on client\nvar q = ctx.Users.Where(u => expanded.Contains(u.Id));\n\n// after (use inside the translated query only)\nvar q = ctx.Users.Where(u => EF.MultipleParameters(ids).Contains(u.Id));","handlingStrategy":"validation","validationCode":"// MultipleParameters must be inside a translated query; verify usage stays server-side\n// (static guard: do not call outside IQueryable expression trees)\npublic static T MultiParamInQuery<T>(IQueryable<T> q, IEnumerable arg)\n    => q.Where(/* uses EF.MultipleParameters(arg) */).First();\n// Never invoke the EF.MultipleParameters value directly.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep EF.MultipleParameters strictly inside the translated query expression.","Avoid wrapping the result in a variable that escapes the query.","Confirm the provider expands multi-parameters for your query shape."],"tags":["efcore","linq","query-translation","client-evaluation"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}