【发布时间】:2009-06-06 14:08:05
【问题描述】:
如何制作一个类似于 SQL Server 中的 where in 子句?
我自己做了一个,但有人可以改进吗?
public List<State> Wherein(string listofcountrycodes)
{
string[] countrycode = null;
countrycode = listofcountrycodes.Split(',');
List<State> statelist = new List<State>();
for (int i = 0; i < countrycode.Length; i++)
{
_states.AddRange(
from states in _objdatasources.StateList()
where states.CountryCode == countrycode[i].ToString()
select new State
{
StateName = states.StateName
});
}
return _states;
}
【问题讨论】: