I set a socket server in c# and im trying to make a program that will show users in current room, their username, their color, etc... I want the server to send to the client all the users who connected to room number 2 and has a red color. If this code was written in mysql, I would do something like that:
SELECT * FROM Clients WHERE Room = '2' AND Color = 'red'
but this is ac# code. not SQL. any help? :)
I think this is what you need:
var color = "Red";
var room = "2";
var myQUery= from client in dbContext.Clients
where client.Room = room && client.Color = color
select client;
You need to follow this tutorial to add linq to sql into your library/project: https://msdn.microsoft.com/en-us/library/bb384428.aspx
Edit: I've included current solution based on the fact that the author is very familiar with SQL syntax.
I personally prefer lambda expressions to query expressions. I would suggest using some like the following:
public IEnumerable<User> getUsers(string color, int room)
{
IEnumerable<User> users = dbContext.Where(x => x.Room == room && x.Color == color);
return users;
}
There are plenty of LINQ tutorials out there.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.