Linq中string转int的方法
2017-05-11 15:58
274 查看
Linq中string转int的方法
在做批量删除时,需把一串id值所对应的数据删除,调试出现问题:Linq语句中如果使用ToString()进行类型转换,编译时不会报错,但执行时会出现如下错误:
“LINQ to Entities 不识别方法"System.String ToString()",因此该方法无法转换为存储表达式。”
原因是Linq不支持ToString()函数。
可用下述方法进行转换解决:
string source = "1,2,3,4,5";
List<int> result = new List<string>(source.Split(',')).ConvertAll(i => int.Parse(i));
注:
需引用下列命名空间
using System.Collections.Generic;
using System.Linq;
相关文章推荐
- Linq中string转int的方法
- JAVA 中int类型转String类型的通常方法,有三种:
- String 的 split(String regex, int limit) 方法 次数,空串
- JavaSE8基础 Integer构造方法 将符合标准的String类型转成int类型
- Java:int 和 String 互相转换的多种方法
- JAVA int float long与String互相转换的方法
- Linq 中string转换为int 取得Max值和Mix值(利用ConvertAll转换)
- Android中 int 和 String 互相转换的多种方法
- Android中 int 和 String 互相转换的多种方法
- Cstring转char、string、int等数据类型的方法
- LINQ to Entities 不识别方法system.string
- Linq LINQ to Entities 不识别方法“System.String ToString(System.Object)”
- JAVA中int、String的类型转换方法汇总及差异
- Cstring转char、string、int等数据类型的方法
- LINQ体验(11)——LINQ to SQL语句之Null语义和String/DateTime方法
- Android中 int 和 String 互相转换的多种方法
- java中将String和int转换的方法
- Android中 int 和 String 互相转换的多种方法
- 从int 到string的几种方法
- ArrayCopy方法int数组、String数组使用实例