I am getting 2100 parameter limit error in a LINQ to SQL query. Here is the procedure which returns the list of id's. Parameter l
has over 5000 id's.
Public Function GetByID(ByVal l As List(Of Int32)) As List(Of OfficeAccess)
Return (From d In db.OfficeAccess
Where l.Contains(d.ID)
Order By d.ID Ascending Select d).ToList()
End Function
I have tried the solution given in the second part of Hitting the 2100 parameter limit (SQL Server) when using Contains() but I'd need another solution without manually building SQL query string and this doesn't work:
Dim ids = String.Join(" ", l.ToArray())
Return(From d In db.OfficeAccess
Where ids.IndexOf(Convert.ToString(d.ID)) != -1
Order By d.ID Ascending Select d).ToList()
Updated
I have used the following code and works fine.
Dim l As New List(Of OfficeAccess)
Dim f As Int32, t As List(Of Int32)
While (ids.Count > 0)
If (ids.Count < 2000) Then f = ids.Count Else f = 2000
t = ids.GetRange(0, f)
l.AddRange((From d In db.OfficeAccess Where t.Contains(d.ID) Select d).ToList())
ids.RemoveRange(0, f)
End While