2017-10-29 48 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;