简体   繁体   English

int的函数类似于string.contains

[英]Function for int similar to string.contains

I have a textbox bind to an int . 我有一个文本框绑定到一个int There is a Search button which gives result on the basis of text in textbox. 有一个搜索按钮,根据文本框中的文本给出结果。 If the text is 12 , all results having 12 should appear. 如果文本为12 ,则应显示所有12的结果。

Such being the case for string , I would have used string.contains . 这就是string的情况,我会使用string.contains But I don't know what to do in case of int . 但我不知道在int情况下该怎么做。

I am using LINQ to filter out results. 我正在使用LINQ来过滤掉结果。

int securityId = Convert.int32(filterColumn.Value, CultureInfo.CurrentCulture);
queryResults=queryResults.Where(generaldata=>generaldata.SecuritiesId.Equals(securityId));  

But this isn't working. 但这不起作用。 I tried following 我试过跟随

string securityId = Convert.ToString(filterColumn.Value, CultureInfo.CurrentCulture);                                
queryResults=queryResults.Where(generaldata=>generaldata.SecuritiesId.ToString().Contains(securityId));  

But getting LINQ exception that I can't use ToString in expression. 但得到LINQ异常,我不能在表达式中使用ToString。

我认为你应该检查少于因为例如,如果你从0到100计数并检查它是否包含12然后是它它包含12因为

12 < 100

Try using SqlFunctions.StringConvert 尝试使用SqlFunctions.StringConvert

string securityId = Convert.ToString(filterColumn.Value, CultureInfo.CurrentCulture);    
queryResults=queryResults
      .Where(gd=>SqlFunctions.StringConvert((double)gd.SecuritiesId).Contains(securityId));

PS: SqlFunctions.StringConvert has no overload for int and that's why the casting to double has been done. PS: SqlFunctions.StringConvert没有int的重载,这就是为什么要完成转换为double的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM