I have LINQ query that returns me the following error: "The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Too many parameters were provided in this RPC request. The maximum is 2100".
All I need is to count all clients that have BirthDate that I have their ID's in list. My list of client ID's could be huge (millions of records).
Here is the query:
List<int> allClients = GetClientIDs();
int total = context.Clients.Where(x => allClients.Contains(x.ClientID) && x.BirthDate != null).Count();
When the query is rewritten this way,
int total = context
.Clients
.Count(x => allClients.Contains(x.ClientID) && x.BirthDate != null);
it causes the same error.
Also tried to make it in different way and it eats all memory:
List<int> allClients = GetClientIDs();
total = (from x in allClients.AsQueryable()
join y in context.Clients
on x equals y.ClientID
where y.BirthDate != null
select x).Count();
GetClientIDsget its data from? If it's pulling it from the db you might want to combine that into your query instead of pulling all the ids to use in a separate query. - juharrallClients.Contains(x.ClientID)forces query to work locally. - Hamlet HakobyanallClientscan be anIQueryablethat contains a linq-to-sql query. If so, it would be incorporated as SQL in thetotalquery. - Gert ArnoldallClients.AsQueryable()not guaranty thatallClientsisIQueryable. Anyway, evenallClientsisIQueryableit not guaranty possibly to translate whole LINQ query to SQL query. - Hamlet Hakobyan