我想知道如何以及如果我可以轻松地查询多个字符串/整数这样的事情?
var test = from a in db.PlasserLans
from b in db.Ulans
where a.registeredNick == b.Username &&
a.Nick == {"Ayuris" , "Crey" , "DjMofasa" , "esel" , "Firaxa" ,
"Kindleguy" , "Michigo" , "moiC" ,"Shibiz"}
orderby a.Nick
select new
{
Nick = a.Nick,
Username = b.Username,
Email = b.UserEMail,
RealName = b.UserRealname,
};
答案 0 :(得分:3)
您可以在查询之前创建列表,这样可以更容易理解。你也可以在两个表上进行连接而不是循环。
List<string> nickList=new List<string> {"Ayuris" , "Crey" , "DjMofasa" , "esel" , "Firaxa" , "Kindleguy" , "Michigo" , "moiC" ,"Shibiz"};
var test = from a in db.PlasserLans
join b in db.Ulans
on a.registeredNick equals b.Username
where nickList.Contains(a.Nick)
orderby a.Nick
select new
{
Nick = a.Nick,
Username = b.Username,
Email = b.UserEMail,
RealName = b.UserRealname,
};
答案 1 :(得分:1)
在Linq-2-sql中它只是相反的方式
where .... &&
{"Ayuris" , "Crey" , "DjMofasa"}.Contains(a.Nick)
这很明确,不确定{}的直接用法是否有效,但你需要检查linq-2-sql的.Contains(),它会起作用。