关于.ToList(): LINQ to Entities does not recognize the method ‘xxx’ method, and this method cannot be translated into a store expression.
LINQ to Entities works by translating LINQ queries to SQL queries, then executing the resulting query on the database and converting the result back to application entities. Because of this crossover of two languages, it will only work when SQL-compatble method calls are made. When an incompatible call is made, it’ll throw an exception along the lines of:
LINQ to Entities does not recognize the method 'xxx' method, and this method cannot be translated into a store expression.
For example the following code will throw this exception:
var result = db.Users.Select(p => new { BirthYear = Convert.ToInt16(p.Year) }).ToList();
Because SQL doesn’t have the .NET based System.Convert class, it can’t translate this call to SQL and hence raises the exception. The way around this is to retrieve the data first, then do any .NET transforms or function calls after:
var result = db.Users.ToList().Select(p => new { BirthYear = Convert.ToInt16(p.Year) }).ToList();
The only difference is that ToList() (or any other method that will execute an IQueryable) is called first that brings the Users data into .NET memory, with the subsequent Convert option done aftewards.
“DataContext accessed after Dispose” error:解决方法,在最后加上.ToList()
关于.ToList(): LINQ to Entities does not recognize the method ‘xxx’ method, and this method cannot be translated into a store expression.的更多相关文章
- 报错:System.NotSupportedException: LINQ to Entities does not recognize the method
报错:System.NotSupportedException: LINQ to Entities does not recognize the method ...... get_Item(Int3 ...
- LINQ to Entities does not recognize the method , and this method cannot be translated into a store expression 解决办法
根据用户输入的起始日期,查询以起始日期开始的前20条记录,在ASP.NET MVC的Controller代码中这样写: var Logs = db.Log.Take(20); if (!string. ...
- LINQ to Entities does not recognize the method 'System.DateTime AddDays(Double)' method, and this method cannot be translated into a store expression.
NormalSubmission=analysis.Count(x=>x.FinishTime<= endTime.AddDays(1))报错linq不能识别 => var endT ...
- LINQ to Entities does not recognize the method 'System.DateTime ToDateTime(System.String)' method
System.Data.Objects.EntityFunctions和System.Data.Objects.SqlClient.SqlFunctions中的方法进行比较,如下 where Syst ...
- LINQ to Entities does not recognize the method 'Int32 ToInt32(System.String)' method, and this method cannot be translated into a store expression
if (!string.IsNullOrEmpty(FarmWorkId)) { data = data.Where(p => p.TypeId == Convert.ToInt32(FarmW ...
- LINQ to Entities不支持Convert.ToDateTime方法解決一例
錯誤提示: LINQ to Entities does not recognize the method 'System.DateTime ToDateTime(System.String)' met ...
- LINQ to Entities 不支持 LINQ 表达式节点类型“ArrayIndex”
我就不屁话,能一张图就解决的就不说话了 2015-03-28 14:53:24,440 [10] ERROR log - System.NotSupportedException: LINQ to E ...
- Linq to entities 学习笔记
Linq to entities ---提供语言集成查询支持用于在概念模型中定义的实体类型. 首先可以根据http://msdn.microsoft.com/en-us/data/jj206878该 ...
- LINQ to Entities不识别方法***,因此该方法无法转换为存储表达式
我的程序里有这么一段代码: order.OrderExpressInfo = (from oei in orderExpressRepository.Entities where oei.OrderI ...
随机推荐
- ES6的编码风格
编程风格 [转自http://es6.ruanyifeng.com/#docs/style] 块级作用域 字符串 解构赋值 对象 数组 函数 Map结构 Class 模块 ESLint的使用 本章探讨 ...
- js【输入一个日期】返回【当前12个月每月最后一天】
Date.prototype.Format = function (fmt) { //author: meizz var o = { "M+": this.getMonth() + ...
- windows phone 8 设置锁屏背景
本来想研究一下 利用闪光灯实现手电筒的代码,发现不是简答设置FlashMode属性可以解决问题的,ms也没有提供api,无意瞄了一眼侧边栏的文章列表,发现了设置屏幕锁屏背景的实现,手一抖点进去了.还算 ...
- jquery上传插件uploadify 报错http error 302 解决方法之一
前段时间用到jquery上传插件uploadify时,始终出现系统报出 http error 302 的错误. 网上大量搜集信息,基本上都是说session值丢失的问题,根据网友提供的解决方案进行修改 ...
- javascript 对象的创建,引用,释放,删除方法
1.用函数构造 A.声明时同时设置属性和方法 function func(){ this.name = "myname"; this.say = function(){aler ...
- AMAZON PRICE TRACKER, AMAZON PRICE HISTORY, AMAZON PRICE DROP ALERT | DROPGG.COM
DropGG.com is the destination for savvy shoppers looking to save money by buying smart. DropGG.com a ...
- SimpleXML解析xml文件
SimpleXML 扩展提供了一种获取 XML 元素的名称和文本的简单方式. 与 DOM 或 Expat 解析器相比,SimpleXML 仅仅用几行代码就可以从 XML 元素中读取文本数据. Simp ...
- TDirectory.GetLogicalDrives获取本地逻辑驱动器
使用函数: System.IOUtils.TDirectory.GetLogicalDrives class function GetLogicalDrives: TStringDynArray; s ...
- xe6+firedac连接sybase
一.Win7 X64系统安装sybase odbc: 1. 下载对应包至c:\system_odbc(文件夹名自己取,在后面注册表内容需要用到): 2. 将值信息写入到注册表内: Windows ...
- 在mac系统安装Apache Tomcat的详细步骤
对于Apache Tomcat 估计很多童鞋都会,那么今天就简单说下在mac上进行tomcat的安装: 第一步:下载Tomcat 这里Himi下载的tomcat version:7. ...