láusula @Where IN no LINQ [duplicado]
Esta pergunta já tem uma resposta aqui:
Linq to Entities - cláusula SQL "IN" 8 respostasComo criar uma cláusula where semelhante a uma no SQL Serve
Fiz um sozinho, mas alguém pode melhorar isso?
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;
}