Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
794 views
in Technique[技术] by (71.8m points)

c# - The incoming request has too many parameters. The server supports a maximum of 2100 parameters

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();

The error I get is this:

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();

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?

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Simple - as long as TheTAbleID's contains less than 2100 ID's then - it is not legal to do that.

Cut the table into blocks of 2000 and then query each block separately, possibly in multiple threads.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...