Get random users
I have a list of user ids and want to get a few random users from a database which doesn't contain users from my list using LINQ-SQL.
For example:
//it's user ids
var existsUsers = new[]{1,2,3,4}
// I want to impl开发者_如何学Goement this function:
List<User> users = GetRandomUsers(randomUsersCount, existsUsers)
Seems that you just can do an Linq In Clause since you have the ids already.
//Not tested.... may have syntax errors.
GetRandomUsers(randomUsersCount, existsUsers)
{
var users= (from u in users
where existsUsers.Contains(u.Id)
select u).Take(randomUserCount);
return users;
}
精彩评论