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 中不能转换类型
随机推荐
- 2017.2.28 activiti实战--第七章--Spring容器集成应用实例(五)普通表单
学习资料:<Activiti实战> 第七章 Spring容器集成应用实例(五)普通表单 第六章中介绍了动态表单.外置表单.这里讲解第三种表单:普通表单. 普通表单的特点: 把表单内容写在 ...
- CentOS SVN 服务器搭建
源码目录:/home/user/project 工程名:project 工程目录:/source/svn/project 访问地址:svn://ip/project 一. 安装svn yum inst ...
- Android 使用意图播放本地视频
Android播放视频的方式有三种: 一.使用意图播放,调用本地安装的播放器,选择一个进行播放. 二.使用VideoView播放(VideoView事实上是对MediaPlayer的封装,使用起来非常 ...
- 常见函数strlen、strcmp、strstr原型实现
数组元素的结束符为'\0'.串的结束符为NULL 一.strlen #include <iostream> using namespace std; long h_strlen(const ...
- Node.js学习笔记(2)——关于异步编程风格
Node.js的异步编程风格是它的一大特点,在代码中就是体现在回调中. 首先是代码的顺序执行: function heavyCompute(n, callback) { var count = 0, ...
- C语言-字符串
问题: 给出的区分大小写的字母字符的字符串,找到最大的字符串X,或者为X,或者其逆可以找到任何给定的字符串的子串 输入: 输入文件的第一行包含一个整数t(1 < = t < = 10),测 ...
- React学习之redux
在阅读本文之前,希望大家对以下知识点能提前有所了解并且上好厕所(文章有点长): 状态提升的概念 react高阶组件(函数) es6基础 pure 组件(纯函数) Dumb 组件 React.js的co ...
- shell函数传递带空格的参数
shell中的参数以空格为分割符,经常会碰到需要传递带空格的参数,例如传递带空格的文件名. 方法很简单:给参数加双引号. 但是实际效果要看你的函数内容,一种可能的情况是: 其实你真的传递进去了带空格的 ...
- MySQL的安装过程
近期对MySQL做了一些研究. 曾经主要接触的是SQL SERVER.所以,今天对该安装过程做了一些总结以及使用过程中的一些心得.并分享给大家. 记得前面.分享过一篇关于数据库的几种连接方式.而 ...
- SpringBoot启动流程分析(三):SpringApplication的run方法之prepareContext()方法
SpringBoot系列文章简介 SpringBoot源码阅读辅助篇: Spring IoC容器与应用上下文的设计与实现 SpringBoot启动流程源码分析: SpringBoot启动流程分析(一) ...