zl程序教程

您现在的位置是:首页 >  其它

当前栏目

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

报错 to The not system does method LinQ
2023-09-11 14:16:51 时间

 

报错: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 };