question

Andrej avatar image
0 Votes"
Andrej asked Viorel-1 answered

IQueriable.Contains how to fix the problem when my collection clearly includes an extremely large number of values

I have query which me need filtering entries, I use IQueriable.Contains(see ex. below). And when my collection clearly includes an extremely large number of values, I get an error: "Error 8623: The query processor ran out of internal resources and could not produce a query plan.".
Code:

         public async Task<IEnumerable<MyModel>> MyMethod(IEnumerable<int> ids, CancellationToken cancellation)
         {
             //ids.Count > 10000
             var foldersQuery = from folder in _dbSet
                                where  ids.Contains(folder.Id)
                                select folder;
    
             return await foldersQuery.ToListAsync(cancellation);
         }

It converts to sql query
select * from Table where Id IN (1, ... 99999)

Could you please me fix this issue, or what can replace it.

dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Viorel-1 avatar image
1 Vote"
Viorel-1 answered

Did you already find the "WhereBulkContains" extension: https://entityframework-extensions.net/where-bulk-contains?


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@Viorel-1 thanks a lot, I haven't found this information before. Your answer helped me solve my problem.

0 Votes 0 ·