Note that there are some explanatory texts on larger screens.

plurals
  1. POLinq .Contains with large set causes TDS error
    primarykey
    data
    text
    <p>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:</p> <pre><code>Parent recno int (unique, pk) date datetime stuff varchar(50) Child parentrecno (int, fk) --- PK sequence (int) --- PK data varchar(50) </code></pre> <p>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:</p> <pre><code>List&lt;int&gt; recs = (from d in Parent where [.....] select d.recno).ToList(); </code></pre> <p>Later on in Linq I can say, find all of the child records for the associated parents:</p> <pre><code>var kids = from k in database.Childs where recs.Contains(k.parentrecno) select new { k }; </code></pre> <p>This is all great until recs contains more than 2100 entries. Then I get a TDS RPC error (too many parameters). </p> <p>The way I see it I can:</p> <ul> <li><p>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.</p></li> <li><p>Break the list (recs) up, and then read Child in chunks.</p></li> </ul> <p>If I break it up in chunks, then my pretty Linq a little farther down won't work at all:</p> <pre><code>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 =&gt; kx.ParentRecNo); </code></pre> <p>Because the List recs will contain things that needed to be grouped together, but necessarily split apart for the Linq query.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload