Linq到实体-SQL“in”子句在T-SQL中,可以有如下所示的查询:SELECT * FROM Users WHERE User_Rights IN ("Admin", "User", "Limited")如何在LINQto实体查询中复制?有可能吗?
3 回答
波斯汪
TA贡献1811条经验 获得超4个赞
查询语法:
var selected = from u in users where new[] { "Admin", "User", "Limited" }.Contains(u.User_Rights) select uforeach(user u in selected){ //Do your stuff on each selected user;}
方法语法:
var selected = users.Where(u => new[] { "Admin", "User", "Limited" }.Contains(u.User_Rights));foreach(user u in selected){ //Do stuff on each selected user;}
foreach(User u in users.Where(u => new [] { "Admin", "User", "Limited" }.Contains(u.User_Rights))){ //Do stuff on each selected user;}
foreach(User u in users.FindAll(u => new [] { "Admin", "User", "Limited" }.Contains(u.User_Rights))){ //Do stuff on each selected user;}
ABOUTYOU
TA贡献1812条经验 获得超5个赞
var desiredNames = new[] { "Pankaj", "Garg" }; var people = new[] { new { FirstName="Pankaj", Surname="Garg" }, new { FirstName="Marc", Surname="Gravell" }, new { FirstName="Jeff", Surname="Atwood" } }; var records = (from p in people join filtered in desiredNames on p.FirstName equals filtered select p.FirstName).ToList();
含有的缺点
List 1 List 2 1 12 2 7 3 8 4 98 5 9 6 10 7 6
- 3 回答
- 0 关注
- 459 浏览
添加回答
举报
0/150
提交
取消