報錯: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 };


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM