LINQ 问题 - 如何使 where != 值
我有一个“朋友”表,其中包含登录用户的 ID 及其朋友的 ID。
我用这个 SQL 查询得到的结果
SELECT u.ID, u.Nickname
FROM UserSet as u, FriendsSet as f
WHERE u.ID=f.FriendID
ORDER BY u.Nickname
是
| ID | Nickname |
-----------------
| 16 | rugardini|
| 17 | Teste |
“rugardini”是我当前的用户,这似乎是因为在友谊关系中“Teste”是我的朋友,我也是他的朋友,但在我的朋友列表中我不希望我的出现自己的用户。
所以我做了以下查询,不包括我自己的 ID (16)
SELECT u.ID, u.Nickname
FROM UserSet as u, FriendsSet as f
WHERE u.ID=f.FriendID and u.ID != 16
ORDER BY u.Nickname
我有 2 个问题:
1) 这是进行此选择的最佳方式吗? 2) 如何将此 SQL 查询转换为 LINQ?
I have a table "Friends" with the ID of the logged user and his/her friend's IDs.
The result I get with this SQL query
SELECT u.ID, u.Nickname
FROM UserSet as u, FriendsSet as f
WHERE u.ID=f.FriendID
ORDER BY u.Nickname
Is
| ID | Nickname |
-----------------
| 16 | rugardini|
| 17 | Teste |
"rugardini" is my current user, it appears because in a friendship relation "Teste" is my friend and I'm his friend too, but in my list of friends I don't want my own user appears.
So I did the following query excluding my own ID (16)
SELECT u.ID, u.Nickname
FROM UserSet as u, FriendsSet as f
WHERE u.ID=f.FriendID and u.ID != 16
ORDER BY u.Nickname
I have 2 questions:
1) Is this the best way of doing this selection?
2) How to convert this SQL query to LINQ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
关于 2):第二个查询的 linq 应该如下所示:
about 2): linq for your second query should look like this:
我只能像这样执行我的查询:
在我的控制器中使用这样的类:
在我的视图中像这样循环:
感谢所有回答我问题的人=)
I could perform my query only like this:
With a class in my controller like this:
And a loop in my view like this:
Thank you for all those who answered my question =)