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.IsNullOrEmpty(dateBegin))
{
Logs = Logs.Where(a => a.Date >= Convert.ToDateTime(dateBegin)).Take();
}
运行后,出现下面错误信息:
对于这种情况,要清楚:本表达式只是LINQ to Entities,而不是真正的C#语言,虽然上述代码在编译是没有错误,但运行时,转换为SQL就产生了错误,无法转换为存储表达式。
解决办法是:将用户输入的起始日期的转换提前一步,使用真正的C#代码完成,然后将转换后的变量代入到LINQ表达式内,修改后的代码可以这样:
var Logs = db.Log.Take(20);
if (!string.IsNullOrEmpty(dateBegin))
{
DateTime dateB = Convert.ToDateTime(dateBegin);
Logs = Logs.Where(a => a.Date >= dateB).Take();
}
可以看到,首先将转换后的日期存入变量dateB内,然后再使用LINQ调用,不在LINQ中直接使用方法。
运行,正常。不再出现错误信息。
LINQ to Entities does not recognize the method , and this method cannot be translated into a store expression 解决办法的更多相关文章
- 关于.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 quer ...
- 报错: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 不识别方法"System.String ToString()",因此该方法无法转换为存储表达式 的解决方法
一.案例1,及解决方案: "LINQ to Entities 不识别方法"System.String ToString()",因此该方法无法转换为存储表达式." ...
- 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 ...
- 关于dubbo调度时出现Request processing failed; nested exception is com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method insertTestTb in the service cn.cuibusi.core.service.TestTbService.的解决办法
在用dubbo跨项目调度service时出现如下错误: 错误原因:pojo没有实现序列化 解决方法:在pojo实现序列化接口即可
- LINQ to Entities不支持Convert.ToDateTime方法解決一例
錯誤提示: LINQ to Entities does not recognize the method 'System.DateTime ToDateTime(System.String)' met ...
- LINQ to Entities 不识别方法“System.String ToString()”,因此该方法无法转换为存储表达式。
var data = DataSource.Skip(iDisplayStart).Take(iDisplayLength).Select(o => new { MatNR = o.MatNR, ...
随机推荐
- Exception in thread "main" java.lang.Error: Unresolved compilation problem
初学java,使用eclipse编译时,可能会遇到如下图所示的编译错误(Exception in thread "main" java.lang.Error: Unresolved ...
- Summary #ToBeContinue......
一.请回望暑假时的第一次作业,你对于软件工程课程的想象1)对比开篇博客你对课程目标和期待,“希望通过实践锻炼,增强计算机专业的能力和就业竞争力”,对比目前的所学所练所得,在哪些方面达到了你的期待和目标 ...
- 试题 F: 特别数的和 第十届蓝桥杯
试题 F: 特别数的和时间限制: 1.0s 内存限制: 512.0MB 本题总分: 15 分[问题描述]小明对数位中含有 2. 0. 1. 9 的数字很感兴趣(不包括前导 0),在 1 到40 中这样 ...
- 深刻理解Java编程的7个例子
1. 阅读下列代码回答问题(第一个Java程序,理解PATH和CLASSPATH,学会使用javac和java命令) package cn.edu.uibe; public class Hell ...
- xml与json的区别和总结
JSON和XML的比较 ◆可读性 JSON和XML的可读性可谓不相上下,一边是简易的语法,一边是规范的标签形式,很难分出胜负. ◆可扩展性 XML天生有很好的扩展性,JSON当然也有,没有什么是XML ...
- shell查找进程并终止
创建kill.sh文件,内容如下: port= #一.根据端口号查询对应的pid,两种都行 pid=$(netstat -nlp | grep :$port | awk '{print $7}' | ...
- C#不能捕捉的异常,如AccessViolationException
在.net的异常机制中,有部分严重的编程错误(系统的某些Corrupted State Exceptions异常)是默认不被用户使用常规的异常捕捉方式捕捉到的. 微软的这种设计方式,是让用户必须处理该 ...
- NETCore 同步AD域组织和用户
BitAdminCore为没有自主开发框架的小团队,提供快速项目搭建及开发能力. 框架演示:http://bit.bitdao.cn 框架源码:https://github.com/chenyinxi ...
- 用 go 写 WebAssembly入门
Golang WebAssembly 入门 Golang 在1.11版本中引入了 WebAssembly 支持,意味着以后可以用 go编写可以在浏览器中运行的程序,当然这个肯定也是要受浏览器沙盒环境约 ...
- 201621123023《Java程序设计》第9周学习总结
一.本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 二.书面作业 1. List中指定元素的删除(题集题目) 1.1 实验总结.并回答:列举至少2种在List中删除 ...