This is my current code:
int[] onlineUsers = GetOnlineArray(); // Cache stored array in example {100,101,102,...,...,...,N}
using (var db = new MyDataContext())
{
var users = (from u in db.Users
where u.u_gender == gender
orderby (onlineUsers.Contains(u.u_username)) descending
select u.u_username).Skip(startRowIndex).Take(maximumRows).ToList();
}
This works but its limited to 2100 online users (because linq pass each array item as a different paramter and sql is limited to 2100 param per query).
The reason for the question above is that i wanted to change this query to use dynamic linq for the orderby. so i built a function that return a sql OR string based on the int[] onlineUsers.
in example
string orderbyQuery = "100 == u.u_username || 101 == u.u_username || 102 == u.u_username"
and the new query is :
using (var db = new MyDataContext())
{
var users = (from u in db.Users
where u.u_gender == gender
orderby (orderByQuery) descending
select u.u_username).Skip(startRowIndex).Take(maximumRows).ToList();
}
but the new query doesn't work.
any idea?