hi casperOne, thanks again.
ill post a better example of my code and maybe you can help me .
it seems that using contains does work (with compiled query) due im not sure if it will work on large amount of users. linq seems to generate a paramter for each user in the int[].
This is my query:
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 is the resulting sql :
exec sp_executesql N'SELECT [t1].[u_username]
FROM (
SELECT ROW_NUMBER() OVER (ORDER BY
(CASE
WHEN [t0].[u_username] IN (@p0, @p1, @p2, @p3, @p4, @p5) THEN 1
WHEN NOT ([t0].[u_username] IN (@p0, @p1, @p2, @p3, @p4, @p5)) THEN 0
ELSE NULL
END) DESC) AS [ROW_NUMBER], [t0].[u_username]
FROM [dbo].[Users] AS [t0]
) AS [t1]
WHERE [t1].[ROW_NUMBER] BETWEEN @p6 + 1 AND @p6 + @p7
ORDER BY [t1].[ROW_NUMBER]',N'@p0 int,@p1 int,@p2 int,@p3 int,@p4 int,@p5 int,@p6 int,@p7 int',@p0=315152,@p1=315151,@p2=315150,@p3=315149,@p4=73621,@p5=36982,@p6=12,@p7=12
1. Do you think its better to use the method you wrote ("create a where clause from each item in the array" - orderby in my case).
2. any change you can write a small example of this function? i dont understand how i can pass the int[] value to the scalar based function ?
THANKS.