{"record":{"id":"f674cf2867c25bb0","repo":"dotnet/efcore","slug":"the-provider-for-the-source-iqueryable-doesn-t-i","errorCode":null,"errorMessage":"The provider for the source 'IQueryable' doesn't implement 'IAsyncQueryProvider'. Only providers that implement 'IAsyncQueryProvider' can be used for Entity Framework asynchronous operations.","messagePattern":"The provider for the source 'IQueryable' doesn't implement 'IAsyncQueryProvider'\\. Only providers that implement 'IAsyncQueryProvider' can be used for Entity Framework asynchronous operations\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Cosmos/Extensions/CosmosQueryableExtensions.cs","lineNumber":249,"sourceCode":"    ///     An optional continuation token returned from a previous execution of this query via\n    ///     <see cref=\"CosmosPage{T}.ContinuationToken\" />. If <see langword=\"null\" />, retrieves query results from the start.\n    /// </param>\n    /// <param name=\"pageSize\">\n    ///     The maximum number of results in the returned <see cref=\"CosmosPage{T}\" />. The page may contain fewer results if the database\n    ///     did not contain enough matching results.\n    /// </param>\n    /// <param name=\"responseContinuationTokenLimitInKb\">Limits the length of continuation token in the query response.</param>\n    /// <param name=\"cancellationToken\">A <see cref=\"CancellationToken\" /> to observe while waiting for the task to complete.</param>\n    /// <returns>A <see cref=\"CosmosPage{T}\" /> containing at most <paramref name=\"pageSize\" /> results.</returns>\n    [Experimental(EFDiagnostics.PagingExperimental)]\n    public static Task<CosmosPage<TSource>> ToPageAsync<TSource>(\n        this IQueryable<TSource> source,\n        int pageSize,\n        string? continuationToken,\n        int? responseContinuationTokenLimitInKb = null,\n        CancellationToken cancellationToken = default)\n        => source.Provider is not IAsyncQueryProvider provider\n            ? throw new InvalidOperationException(CoreStrings.IQueryableProviderNotAsync)\n            : provider.ExecuteAsync<Task<CosmosPage<TSource>>>(\n                Expression.Call(\n                    instance: null,\n                    method: new Func<IQueryable<TSource>, int, string?, int?, CancellationToken, Task<CosmosPage<TSource>>>(ToPageAsync)\n                        .Method,\n                    arguments:\n                    [\n                        source.Expression,\n                        Expression.Constant(pageSize, typeof(int)),\n                        Expression.Constant(continuationToken, typeof(string)),\n                        Expression.Constant(responseContinuationTokenLimitInKb, typeof(int?)),\n                        Expression.Constant(default(CancellationToken), typeof(CancellationToken))\n                    ]),\n                cancellationToken);\n}\n","sourceCodeStart":231,"sourceCodeEnd":265,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Cosmos/Extensions/CosmosQueryableExtensions.cs#L231-L265","documentation":"ToPageAsync requires the IQueryable's Provider to implement IAsyncQueryProvider (EF's provider). A plain LINQ provider — e.g. from List<T>.AsQueryable(), an in-memory IEnumerable, or a non-EF wrapper — does not, so the method throws InvalidOperationException via CoreStrings.IQueryableProviderNotAsync before executing.","triggerScenarios":"Calling ToPageAsync on myList.AsQueryable(); on a query built from an in-memory source; on a wrapped/fake IQueryable in a unit test that is not backed by an EF provider; composing over a DbSet that was replaced by a stub.","commonSituations":"Unit-testing Cosmos paging with a hand-rolled IQueryable; passing a materialized list back through a repository that returns IQueryable; using a mocking library that returns a non-async provider.","solutions":["Call ToPageAsync on a real EF DbSet<T>/IQueryable obtained from the DbContext.","Do not call .AsQueryable() on an in-memory collection before ToPageAsync.","In tests, use the EF in-memory or test double provider that implements IAsyncQueryProvider rather than List.AsQueryable()."],"exampleFix":"// before (in-memory list provider is not async)\nvar page = await _cache.AsQueryable()\n    .ToPageAsync(pageSize: 20, continuationToken: token);\n\n// after (real EF queryable)\nvar page = await _context.Items\n    .ToPageAsync(pageSize: 20, continuationToken: token);","handlingStrategy":"type-guard","validationCode":"// Ensure the source provider supports async before paging.\nif (source.Provider is not IAsyncQueryProvider)\n    throw new InvalidOperationException(\"ToPageAsync requires an EF queryable (IAsyncQueryProvider).\");\nreturn await source.ToPageAsync(pageSize, token);","typeGuard":"static bool IsEfAsyncQueryable<T>(IQueryable<T> q) => q.Provider is IAsyncQueryProvider;","tryCatchPattern":"try { return await source.ToPageAsync(pageSize, token); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"IAsyncQueryProvider\"))\n{ throw new InvalidOperationException(\"Pass a DbSet/IQueryable from the DbContext, not an in-memory AsQueryable().\", ex); }","preventionTips":["Call ToPageAsync only on DbSet<T> or EF queryables from the DbContext.","Never call List<T>.AsQueryable() before paging.","In unit tests, use an EF provider test double that implements IAsyncQueryProvider."],"tags":["cosmos","paging","async-query","query-provider"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}