一、案例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,及解决方案:

//获取市级地区public JsonResult
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()",因此该方法无法转换为存储表达式。”

解决方案一:

//获取市级地区public JsonResult
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); }

解决方案二:

using System.Data.Objects.SqlClient;  //在 System.Data.Entity.dll
//获取市级地区public JsonResult
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()",因此该方法无法转换为存储表达式 的解决方法的更多相关文章

  1. Linq中字段数据类型转换问题(Linq to entity,LINQ to Entities 不识别方法"System.String ToString()"问题解决)

    1.在工作中碰到这样一个问题: 使用linq时,需要查询两个表,在这两张表中关联字段分别是int,和varchar()也就是string,在linq中对这两个字段进行关联, 如果强制类型转换两个不同类 ...

  2. LINQ to Entities 不识别方法“System.String ToString()”,因此该方法无法转换为存储表达式。

    var data = DataSource.Skip(iDisplayStart).Take(iDisplayLength).Select(o => new { MatNR = o.MatNR, ...

  3. LINQ to Entities 不识别方法“System.String ToString(System.String)”,因此该方法无法转换为存储表达式。

    来源:https://www.cnblogs.com/hao-1234-1234/p/9112434.html 6  Select的时候,时间无法转换成 年月日  YYMMMdd 报错:LINQ to ...

  4. linq to entity不识别方法"System.String ToString()"

    将班级id以字符串形式输入如:"1111,1112,1113".数据库里的id为int型,在数据路里找到匹配的相应班级转换成列表.在这里爆出问题:不识别方法"System ...

  5. LinQ to entities 不能识别方法“system.string.ToString(system.String)”.因此该方法无法转换为存储表达式

    [我也是刚研究IEnumerable和IQueryable]以下都是个人理解,仅供参考,如有错误欢迎指出~ 在EF里面,使用IQueryable和IEnumerable可以延迟加载. IQueryba ...

  6. LINQ to Entities 不识别方法“System.String ToString(“yyyy-MM-dd”)”

    将Queryable转化为IEnumerable或者直接Tolist()

  7. mvc ef LINQ to Entities 不识别方法“Int32 Parse(System.String)”,因此该方法无法转换为存储表达式。

    private sys_User GetUserInfo() { sys_User model = null; var userId = Convert.ToInt32(AccountHelper.G ...

  8. LINQ to Entities 不识别方法“System.String get_Item(Int32)”,因此该方法无法转换为存储表达式。

    1.LINQ to Entities 不识别方法“System.String get_Item(Int32)”,因此该方法无法转换为存储表达式.项目中发现linq to entities 不识别? , ...

  9. LINQ to Entities 不识别方法“System.Guid Parse(System.String)”,因此该方法无法转换为存储表达式。

    LINQ to Entities 不识别方法"System.Guid Parse(System.String)",因此该方法无法转换为存储表达式. linq 中不能转换类型

随机推荐

  1. 转:代码管理技巧——两步创建本地SVN服务器图文教程

    from: http://www.cnblogs.com/tianhonghui/archive/2012/07/22/2603454.html   当我们进行开发的时候,不论是独立开发还是处在团队中 ...

  2. HTML5 Canvas 绘制佛教万字

    代码如下: <!DOCTYPE html> <html lang="utf-8"> <meta http-equiv="Content-Ty ...

  3. 伪静态对struts action的重写

    参见 http://ocaicai.iteye.com/blog/1312189 最重要的而是在web.xml中配置 <filter-mapping> <filter-name> ...

  4. apache压缩页面, 全面加速网站

    介绍: 网页压缩来进一步提升网页的浏览速度,它完全不需要任何的成本,只不过是会让您的服务器CPU占用率稍微提升一两个百分点而已或者更少.   原理:   网页压缩是一项由 WEB 服务器和浏览器之间共 ...

  5. XMPP系列(三)---获取好友列表、加入好友

    1.心跳检測.掉线重连功能 client和server端都能够设置多久发送一次心跳包,假设对方没有返回正确的pong信息,则会断开连接,而加入掉线重连功能,则会自己主动进行连接. 假设自己写聊天功能还 ...

  6. H5网页判断手机横屏或是竖屏

    我们做出来的H5页面在手机端浏览的时候,用户很有可能会产生更换横竖屏的操作,这时如果我们能够判断出横竖屏,就可以更好的优化我们的网页,进而拥有更好的用户体验度.下面是判断横竖屏的代码: window. ...

  7. hibernate出现 org.hibernate.PropertyNotFoundException: field [departmen] not found on cn.itcast.hibernate.domain.Employee1错误

    hibernate出现 org.hibernate.PropertyNotFoundException: field [departmen] not found on cn.itcast.hibern ...

  8. 【selenium】Selenium基于Python3的Web自动化测试脚本在IE上运行慢的解决方法

    阐述问题: 执行自动化脚本时,发现文本输入在IE浏览器上特别慢,这样大大降低了自动化效率 解决办法:原因是原先下载的IEDriverServer.exe为64位系统的IE,换为32位的IEDriver ...

  9. C# Array类的浅复制Clone()与Copy()的差别

    1 Array.Clone方法 命名空间:System 程序集:mscorlib 语法: public Object Clone() Array的浅表副本仅复制Array的元素,不管他们是引用类型还是 ...

  10. MongoDB安装配置(Windows)

    官网下载:https://www.mongodb.com/ 百度经验:https://jingyan.baidu.com/article/d5c4b52bef7268da560dc5f8.html 官 ...