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