凡在LINQ条款 [英] Where IN clause in LINQ
本文介绍了凡在LINQ条款的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何让其中在SQL Server中相似的一个条款?
我做了一个我自己,但任何人都可以请改善这个?
公开名单<州与GT;其中(串listofcountry codeS)
{
字符串[]国家code = NULL;
国家code = listofcountry codes.Split('');
清单<州与GT; statelist =新的List<州及GT;(); 的for(int i = 0; I<国家code.Length;我++)
{
_states.AddRange(
从_objdatasources.StateList州()
其中,states.Country code ==国家code [I]的ToString()
选择新的国家
{
Statename的= states.StateName });
}
返回_states;
}
解决方案
这前pression应该做你想要达到的目标。
dataSource.StateList.Where(S = GT;国家codes.Contains(s.Country code)条)
How to make a where in clause similar to one in SQL Server?
I made one by myself but can anyone please improve this?
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;
}
解决方案
This expression should do what you want to achieve.
dataSource.StateList.Where(s => countryCodes.Contains(s.CountryCode))
这篇关于凡在LINQ条款的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文