一、案例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. CSRF到底 是个什么玩意?

    CSRF CSRF(Cross-site request forgery)跨站请求伪造,也被称为"One Click Attack"或者Session Riding,通常缩写为CS ...

  2. redis实现訪问频次限制的几种方式

    结合上一篇文章<redis在学生抢房应用中的实践小结>中提及的用redis实现DDOS设计时遇到的expire的坑.事实上,redis官网中对incr命令的介绍中已经有关于怎样用redis ...

  3. Linux 安装、卸载程序

    一, RPM 安装:        rpm -ivh xxx.rpm 重新安装: rpm -ivh -replacepkgs xxx.rpm 卸载:       rpm -e xxx.rpm 二,ta ...

  4. SQL检索语句及过滤语句

    首先推荐一款比较好用的数据库管理软件:navicat premium. 数据库中最重要的检索功能:SELECT语句 1.检索单个列:select 列名 from 表名: 2.检索多个列:select ...

  5. Nginx绑定多个域名的方法

        nginx绑定多个域名可又把多个域名规则写一个配置文件里,也可又分别建立多个域名配置文件,我一般为了管理方便,每个域名建一个文件,有些同类域名也可又写在一个总的配置文件里.  一.每个域名一个 ...

  6. MySQL 优化、设计规则浅谈

    当数据量大,数据库相应慢时都会针对数据库进行优化.这时都是要针对具体情况,具体业务需求进行优化的. 但是有些步骤和规则应该适合各种情况的.这里综合网上找的资料简单分析一下. 第一优化你的sql和索引: ...

  7. eclipse不能添加tomcat

    有时候原来能新建server,删掉后就不能新建了 1.退出eclipse 2.到[工程目录下 workspace ]/.metadata/.plugins/org.eclipse.core.runti ...

  8. HTML5实现两个视频循环播放!

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. golang生成随机函数的实现

    golang生成随机数可以使用math/rand包, 示例如下: package main import ( "fmt" "math/rand" ) func ...

  10. EntityFramwork 查询

    EntityFramwork 查询 1.简单查询: SQL: SELECT * FROM [Clients] WHERE Type=1 AND Deleted=0 ORDER BY ID EF: // ...