开发者

Get random users

开发者 https://www.devze.com 2023-02-19 16:50 出处:网络
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.

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;

}
0

精彩评论

暂无评论...
验证码 换一张
取 消