2017-10-29 44 views
-1
 var query = from c in countryStates 
        where (c.CountryStateID.ToString().Contains(_RestrictCountryStateID)) 
        orderby c.CountryStateDesc 
        select c; 

在此代码_RestrictCountryStateID是一个字符串,其中包含CountrySateIDs ,我不知道每个查询我有_RestrictCountryStateID中有多少CountrySateIDs。如何在C#中使用linq查询中的experssion动态?

如何写出这个场景的地方?

+0

此查询没有工作。 –

回答

0

使_RestrictCountryStateID逗号分隔的字符串。然后以下将工作:

var ids = _RestrictCountryStateID.Split(','); 
var query = from c in countryStates where ids.Contains(c.CountryStateID) 
        orderby c.CountryStateDesc 
        select c;