日期:2014-05-20  浏览次数:20923 次

Linq,遍历追加条件查询
 
string sb = "aa,bb,cc";
string[] str = sb.Split(new char[] { ',' });
var dm = from d in es.Dept_Manage
  select d;

foreach(string s in str)
{
  dm = dm.Where(i => i.name.Equals(str));
}

我想把查询条件变成这样的:我写的是SQL语句啊
select * from a where a.name = 'aa' or a.name = 'bb' or a.name ='cc'

上面的遍历应该怎么该 才能达到下面的效果呢?

------解决方案--------------------
何必用到什么foreach呢,这样就够了
C# code

string sb = "aa,bb,cc"; 
string[] str = sb.Split(new char[] { ',' }); 
var dm = from d in es.Dept_Manage where str.Contains(d.name)
        select d;