传入请求的参数太多.服务器最多支持2100个参数 [英] The incoming request has too many parameters. The server supports a maximum of 2100 parameters
问题描述
我有这个看似简单的linq-to-sql查询,它在几列中搜索一些数据;像这样的东西:
I have this seemingly simple linq-to-sql query that searches some data in several columns; something like this:
List<long> TheTableIDs = list of IDs (sometimes more than 2100)
var QueryOutput = (from x in TheDataContext.SomeTable
where TheTableIDs.Contains(x.ID) &&
x.Col1.Contains(SomeString) ||
x.Col2.Contains(SomeString))
select x.ID).ToList();
我得到的错误是:
其他信息:传入请求的参数太多. 该服务器最多支持2100个参数.减少数量 参数并重新发送请求.
Additional information: The incoming request has too many parameters. The server supports a maximum of 2100 parameters. Reduce the number of parameters and resend the request.
解决此问题的最佳方法是什么?
What's the best way to solve this?
我环顾四周,找到的解决方案如下:
I've looked around and a solution I found looks like this:
var QueryOutput = TheDataContext.SomeTable.AsEnumerable()
.Join(TheTableIDs, x => x.LeadID, ci => ci, (x, ci) => x)
.Where(x => SomeString.Contains(x.Col1) == true ||
SomeString.Contains(x.Col2) == true)
.Select(x => x.ID).ToList();
这会编译并且不会引发任何异常,但是似乎会忽略带有SomeString.Contains
This compiles and doesn't throw any exceptions but seems to ignore the Where
clauses with SomeString.Contains
使该查询起作用的解决方案是什么?
What's the solution to make this query work?
谢谢.
推荐答案
简单-只要TheTAbleID包含的ID少于2100,那么-这样做是不合法的.
Simple - as long as TheTAbleID's contains less than 2100 ID's then - it is not legal to do that.
将表切成2000个块,然后分别(可能在多个线程中)分别查询每个块.
Cut the table into blocks of 2000 and then query each block separately, possibly in multiple threads.
这篇关于传入请求的参数太多.服务器最多支持2100个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!