0

I am building a linq-to-sql web application and I've encountered a problem. I am trying to use the user's friends list fetched in real time from facebook, and then joining them against SQL tables.

For that I am usually using .Contains(friends) where friends are the User IDs. the problem is that LINQ will not be able to use .contains(friends) when friends are more than 2100 values and I am getting an exception.

So my question is - what is the best practice for reading on the fly the user's friends and joining that with my SQL tables?

Thanks y'all!

Himberjack
  • 5,682
  • 18
  • 71
  • 115

1 Answers1

2

Issue multiple queries, each querying at most 2100 values. The problem that you are seeing is that SQL Server can only accept 2100 SQL parameters per query batch.

In that sense your problem has nothing to do with Facebook. It is a SQL Server limitation triggered by the type of query that LINQ to SQL decides to send (and there is no way to make it send the query differently).

usr
  • 168,620
  • 35
  • 240
  • 369
  • Yes I know. I am just examplaing with the facebook to show that I dont have the relevent facebookIDs in a table in the SQL, but in-memory data – Himberjack Oct 28 '12 at 14:29
  • @Himberjack the Facebook issue aside, does my answer help you resolve the problem? – usr Oct 28 '12 at 15:33
  • i think its hacky to page the query... but I guess I will test to see how "heavy" this is – Himberjack Oct 28 '12 at 16:53
  • There is no other choice, besides to fall back to raw SQL and use table values parameters of course. – usr Oct 28 '12 at 17:39