报错:System.NotSupportedException: LINQ to Entities does not recognize the method_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > 报错:System.NotSupportedException: LINQ to Entities does not recognize the method

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

 2015/4/24 17:11:59  Darren Ji  程序员俱乐部  我要评论(0)
  • 摘要:报错:System.NotSupportedException:LINQtoEntitiesdoesnotrecognizethemethod......get_Item(Int32)'method,andthismethodcannotbetranslatedintoastoreexpression.在控制器中有如下一段代码:vartempList=SomeService.LoadEntities(c=>c.DelFlag==(short)DelFlagEnum.Normal)
  • 标签:system not

 

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

 

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

 

monospace; width: 100%; margin: 0em; background-color: #f0f0f0">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 };
发表评论
用户名: 匿名