I want to run this LINQ simple code to have record number in LINQ but result is beneath error
var model = _db2.Persons.Select(
(x, index) => new
{
rn = index + 1,
col1 = x.Id
}).ToList();
Error:
LINQ to Entities does not recognize the method 'System.Linq.IQueryable
1[<>f__AnonymousType22 [System.Int32,System.Int32]] Select[Person,<>f__AnonymousType22](System.Linq.IQueryable1 [MvcApplication27.Models.Person], System.Linq.Expressions.Expression1[System.Func3 [MvcApplication27.Models.Person,System.Int32,<>f__AnonymousType2`2 [System.Int32,System.Int32]]])' method, and this method cannot be translated into a store expression.
Personsis notIQueryable, try usingCastorOfType(of course if they are present) first. - King KingSystem.Linq.IQueryableis the return type, not the method name. The stuff you see in the square brackets ([<>f__AnonymousType22 [System.Int32,System.Int32]]) is the stuff that would be in the<int, f__AnonymousType22<>>if you where to type it out. The actual function is after that sectionSelect[Person,<>f_AnonymousType22](...). - Scott Chamberlain