报错: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 };
posted @ 2015-04-24 15:21  Darren Ji  阅读(3498)  评论(0编辑  收藏  举报

我的公众号:新语新世界,欢迎关注。