I've oversimplified this a bit, because I'm looking for a general-purpose answer. Let's say I've got a table setup like this:
Parent
recno int (unique, pk)
date datetime
stuff varchar(50)
Child
parentrecno (int, fk) --- PK
sequence (int) --- PK
data varchar(50)
And in my C# program I've gone through a lot of hassle to find the Parent records that I'm interested in and stuff them into a list. Parent is a really large table, and I'd rather not query it more than necessary. So I squirrel away the keys:
List<int> recs = (from d in Parent where [.....] select d.recno).ToList();
Later on in Linq I can say, find all of the child records for the associated parents:
var kids = from k in database.Childs
where recs.Contains(k.parentrecno)
select new { k };
This is all great until recs contains more than 2100 entries. Then I get a TDS RPC error (too many parameters).
The way I see it I can:
Do the whole thing in straight up SQL (didn't really want to do go through the hassle with a DataReader, etc...). There was an external system involved in qualifying the records, so I don't know if that's entirely possible either. Plus, I'd be generating that list twice -- once when I need to use it in .Contains(), and again for other purposes.
Break the list (recs) up, and then read Child in chunks.
If I break it up in chunks, then my pretty Linq a little farther down won't work at all:
var kids2 = (from kid in paydb.Childs
where
recs.Contains(kid.parentrecno)
group pay by kid.parentrecno into kgroup
select new { ParentRecNo = kgroup.Key, KidRecords = kgroup })
.ToDictionary(kx => kx.ParentRecNo);
Because the List recs will contain things that needed to be grouped together, but necessarily split apart for the Linq query.