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

后端 未结 6 1128
野性不改
野性不改 2020-12-16 10:33

I have this seemingly simple linq-to-sql query that searches some data in several columns; something like this:

List TheTableIDs = list of IDs (s         


        
6条回答
  •  隐瞒了意图╮
    2020-12-16 11:32

    SQL doesn't support more than 2100 values in in statement, but you can use in with table with more than 2100 rows so you can insert your data into a table and change your query to check the in with selecting from that table

    for example

    Create TempIDs (bigint ID, uniqueidentifier guid)
    

    guid column is for preventing mixing different user data

    in your code

    Guid myKey = Guid.New();
    List TheTableIDs = list of IDs (sometimes more than 2100)
    TheDataContext.TempIDs.InsertAllOnSubmit(TheTableIDs.select(i => new TempIDs{ID = i, Guid = mykey});
    TheDataContext.SubmitChanges();
    
    var QueryOutput = (from x in TheDataContext.SomeTable
    
                       where TheDataContext.TempIDs.Contains(x.ID) &&
    
                       x.Col1.Contains(SomeString) || 
                       x.Col2.Contains(SomeString))
    
                       select x.ID).ToList();
    

    also if you can retrive the ids from database , you can write a table value function in sql to return the ids and model this function in your code, let say its name is fnGetIds. Then use it in your code as below

    var QueryOutput = (from x in TheDataContext.SomeTable
    
                       where TheDataContext.fnGetIds().Contains(x.ID) &&
    
                       x.Col1.Contains(SomeString) || 
                       x.Col2.Contains(SomeString))
    
                       select x.ID).ToList();
    

提交回复
热议问题