LINQ to Entities 不识别方法"System.String ToString()",因此该方法无法转换为存储表达式 的解决方法
一、案例1,及解决方案:
“LINQ to Entities 不识别方法"System.String ToString()",因此该方法无法转换为存储表达式。”
原因是LINQ to Entities 不支持ToString()函数。
可用下述方法进行转换解决:
string str= "1,2,3,4,5,6,7,8,9,0";
List<int> result = new List<string>(str.Split(',')).ConvertAll(i => int.Parse(i));
return dal.T_Common_Dy.Where(m => result.Any(a => a == m.ParentItemID.Value)).ToList();
二、案例2,及解决方案:
GetCity(string id) { var city = from
c in db.AreaDivide wherec.ParentID ==int.Parse(id) select new {
text =c.AreaName, value = c.ID
}; return Json(city.ToList(), JsonRequestBehavior.AllowGet); }
以上代码也会出现如下错误:
“LINQ to Entities 不识别方法"System.String ToString()",因此该方法无法转换为存储表达式。”
解决方案一:
GetCity(string id) { int a; int.TryParse(id, out a);
var city = from c in db.AreaDivide wherec.ParentID== a select new {
text = c.AreaName, value = c.ID
}; return Json(city.ToList(), JsonRequestBehavior.AllowGet); }
解决方案二:
中
GetCity(string id) { var city = from
c in db.AreaDivide whereSqlFunctions.StringConvert((double)c.ParentID)== id select new {
text = c.AreaName, value = c.ID
}; return Json(city.ToList(), JsonRequestBehavior.AllowGet); }
LINQ to Entities 不识别方法"System.String ToString()",因此该方法无法转换为存储表达式 的解决方法的更多相关文章
- Linq中字段数据类型转换问题(Linq to entity,LINQ to Entities 不识别方法"System.String ToString()"问题解决)
1.在工作中碰到这样一个问题: 使用linq时,需要查询两个表,在这两张表中关联字段分别是int,和varchar()也就是string,在linq中对这两个字段进行关联, 如果强制类型转换两个不同类 ...
- LINQ to Entities 不识别方法“System.String ToString()”,因此该方法无法转换为存储表达式。
var data = DataSource.Skip(iDisplayStart).Take(iDisplayLength).Select(o => new { MatNR = o.MatNR, ...
- LINQ to Entities 不识别方法“System.String ToString(System.String)”,因此该方法无法转换为存储表达式。
来源:https://www.cnblogs.com/hao-1234-1234/p/9112434.html 6 Select的时候,时间无法转换成 年月日 YYMMMdd 报错:LINQ to ...
- linq to entity不识别方法"System.String ToString()"
将班级id以字符串形式输入如:"1111,1112,1113".数据库里的id为int型,在数据路里找到匹配的相应班级转换成列表.在这里爆出问题:不识别方法"System ...
- LinQ to entities 不能识别方法“system.string.ToString(system.String)”.因此该方法无法转换为存储表达式
[我也是刚研究IEnumerable和IQueryable]以下都是个人理解,仅供参考,如有错误欢迎指出~ 在EF里面,使用IQueryable和IEnumerable可以延迟加载. IQueryba ...
- LINQ to Entities 不识别方法“System.String ToString(“yyyy-MM-dd”)”
将Queryable转化为IEnumerable或者直接Tolist()
- mvc ef LINQ to Entities 不识别方法“Int32 Parse(System.String)”,因此该方法无法转换为存储表达式。
private sys_User GetUserInfo() { sys_User model = null; var userId = Convert.ToInt32(AccountHelper.G ...
- LINQ to Entities 不识别方法“System.String get_Item(Int32)”,因此该方法无法转换为存储表达式。
1.LINQ to Entities 不识别方法“System.String get_Item(Int32)”,因此该方法无法转换为存储表达式.项目中发现linq to entities 不识别? , ...
- LINQ to Entities 不识别方法“System.Guid Parse(System.String)”,因此该方法无法转换为存储表达式。
LINQ to Entities 不识别方法"System.Guid Parse(System.String)",因此该方法无法转换为存储表达式. linq 中不能转换类型
随机推荐
- .NET创建宿主设计器--DesignHost、DesignSurface.
一个窗口在运行时,是这样的: 但是,在设计时,却远比这复杂的多,它需要一个设计器对象:它仅存在于设计时,并连接到运行时存在的对象. 宿主容器 我们可以看到每个窗体和按钮均有与之相关的设计器.这两个 ...
- HDU 3591 The trouble of Xiaoqian(多重背包+全然背包)
HDU 3591 The trouble of Xiaoqian(多重背包+全然背包) pid=3591">http://acm.hdu.edu.cn/showproblem.php? ...
- 工厂方法模式之C++实现
说明:本文仅供学习交流,转载请标明出处.欢迎转载. 工厂方法模式与简单工厂模式的差别在于:在简单工厂模式中.全部的产品都是有一个工厂创造,这样使得工厂承担了太大的造产品的压力,工厂内部必须考虑所以的产 ...
- 转:static关键字的总结
static关键字的总结 C++的static有两种用法:面向过程程序设计中的static和面向对象程序设计中的static.前者应用于普通变量和函数,不涉及类:后者主要说明static在类中的作用. ...
- 自己定义ViewGroup控件(二)----->流式布局进阶(二)
main.xml <?xml version="1.0" encoding="utf-8"? > <com.example.SimpleLay ...
- js中insertAdjacentHTML的玩法
原型:insertAdajcentHTML(swhere,stext) insertAdjacentHTML方法:在指定的地方插入html标签语句 参数:swhere: 指定插入html标签语句的地方 ...
- 【Selenium+Python Webdriver】报错之:TypeError: user_login() missing 1 required positional argument: 'self'
先贴一下源码: base.py文件如下: from selenium import webdriver class Page(object): ''' 页面基础类,用于所有页面的继承 ''' rb_u ...
- 【TensorFlow-windows】(七) CNN之VGG-net的测试
主要内容: 1.CNN之VGG-net的测试 2.该实现中的函数总结 平台: 1.windows 10 64位 2.Anaconda3-4.2.0-Windows-x86_64.exe (当时TF还不 ...
- eclipse集成tomcat改动字符集參数
问题: 在eclipse 4.4(Luna)中集成tomcat时,直接改动原tomcat文件夹中的配置文件,不起作用. 有时.我们会修改字符集參数为utf-8,以解决中文乱码问题,修改之后依旧乱码-- ...
- jquery实现重置
$('#reset').click(function(){ $('#info_frm')[0].reset(); });