报错:System.NotSupportedException: LINQ to Entities does not recognize the method

报错:System.NotSupportedException: LINQ to Entities does not recognize the method ...... get_Item(Int32)‘ method, and this method cannot be translated into a store expression.

在控制器中有如下一段代码:

var tempList = SomeService.LoadEntities(c => c.DelFlag == (short)DelFlagEnum.Normal);

var result = from l in tempList
             select new { n = l.Name, a = l.Age };

LoadEntities方法返回的类型是IQueryable<T>,如果要对集合用Select方法,在用Select方法之前需要ToList一下。

修改成:

var result = from l in tempList.ToList()
             select new { n = l.Name, a = l.Age };

时间: 2024-08-12 07:25:41

报错:System.NotSupportedException: LINQ to Entities does not recognize the method的相关文章

LINQ to Entities does not recognize the method &#39;System.DateTime ToDateTime(System.String)&#39; method

System.Data.Objects.EntityFunctions和System.Data.Objects.SqlClient.SqlFunctions中的方法进行比较,如下 where System.Data.Objects.SqlClient.SqlFunctions.DateDiff("s",DateTime.Now,u.Time)>0 where System.Data.Objects.EntityFunctions.DiffSeconds(DateTime.Now,

LINQ to Entities does not recognize the method &#39;Int32 ToInt32(System.String)&#39; method, and this method cannot be translated into a store expression

if (!string.IsNullOrEmpty(FarmWorkId)) { data = data.Where(p => p.TypeId == Convert.ToInt32(FarmWorkId)); } 解决方法: if (!string.IsNullOrEmpty(FarmWorkId)) { int i = Convert.ToInt32(FarmWorkId); data = data.Where(p => p.TypeId == i); } LINQ to Entities

C# 调用win32 DLL报错 System.BadImageFormatException

C# 调用win32 DLL报错  System.BadImageFormatException 项目右键属性->项目设计器->生成->平台->把'默认设置(任何 CPU)'改为x86. 因为'任何 CPU'的程序在64位的机器上就会用运行为64位,而64程序是不能加载32位dll的

.NET下载文件报错System.UnauthorizedAccessException的解决方法

转自原文.NET下载文件报错System.UnauthorizedAccessException的解决方法 假设VS代码对应路径为E:\Projects\Web1,在VS用“发布Web”的方式发布后的路径为E:\Site\Web1.在IIS新建2个站点,站点A指向E:\Projects\Web1,站点B指向E:\Site\Web1. 现在出现一个异常情况,站点B能正常下载123.xls,站点A下载时却提示错误: System.UnauthorizedAccessException: 对路径“E:

ASP.NET MVC页面报错System.InvalidOperationException The view found at &#39;~/Views/Home/Index.cshtml&#39; was not created.

Application Exception System.InvalidOperationException The view found at '~/Views/Home/Index.cshtml' was not created. Description: HTTP 500.Error processing request. Details: Non-web exception. Exception origin (name of application or object): System

[Android]通过js方法回调部分native报错 Web Console: Uncaught TypeError: Object [object Object] has no method &#39;xxx&#39;

在android4.2以前,注入步骤如下: webview.getSetting().setJavaScriptEnable(true); class JsObject { public String toString() { return "injectedObject"; } } webView.addJavascriptInterface(new JsObject(), "injectedObject"); Android4.2及以后,注入步骤如下: webv

Spring Boot报错Error creating bean with name &#39;userRepository&#39;: Invocation of init method failed; nested exception

问题:出现UserRePository注入创建失败,一定先检查所有的@注解是否已经标记 问题发现:entity下的实体类上面没有加注解  任何基于hibernate的实体类一定要加上@Entity注解! Spring Boot报错Error creating bean with name 'userRepository': Invocation of init method failed; nested exception 原文地址:https://www.cnblogs.com/my-prog

ef core 自引用类 报错System.Text.Json.JsonException: A possible object cycle was detected which is not supported....

ef core 创建自引用灰了了 public class Menu:IEntity { public int Id { get; set; } public string text { get; set; } public bool group { get; set; } public bool shortout_root { get; set; } public string link { get; set; } public string icon { get; set; } public

Oracle.DataAccess.Client.OracleConnection.Open()报错System. NullReferenceException

使用ODAC链接Oracle数据库时,conn.Open()报错:未将对象的实例设置到对象引用. Oracle.DataAccess.dll版本:4.121.2.0 ODAC RELEASE 4 OracleClient版本:Oracle 12c Release 4 方案一(验证可行): (1)服务器安装32-bit ODAC with Oracle Developer Tools for Visual Studio Downloads,下载地址:http://www.oracle.com/te