[英]get data about clients in server socket C#
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. 我在c#中设置了一个套接字服务器,我正在尝试创建一个程序,用于显示当前房间中的用户,用户名,颜色等...我希望服务器向连接到房间号2的所有用户发送给客户端并且有红色。 If this code was written in mysql, I would do something like that:
如果这段代码是用mysql编写的,我会做类似的事情:
SELECT * FROM Clients WHERE Room = '2' AND Color = 'red'
but this is ac# code. 但这是ac#code。 not SQL.
不是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 您需要按照本教程将linq添加到您的库/项目中: http : //psdn.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. 编辑:基于作者非常熟悉SQL语法的事实,我已经包含了当前的解决方案。
I personally prefer lambda expressions to query expressions. 我个人更喜欢使用lambda表达式来查询表达式。 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. 有很多LINQ教程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.