LINQ to Entities does not recognize the method ElementAt(i);

后端 未结 2 348
南方客
南方客 2021-01-08 00:28

I\'m using the method elementat(Int32) to get a specific element of a query\'s result.

var mds = db.TDP_MissioniDestinazioni.Where(p => p.Mis         


        
相关标签:
2条回答
  • 2021-01-08 01:16

    Are you happy to fetch all the "earlier" results? If so, either call ToList() to cache them, or AsEnumerable() to fetch them on each call, with the AsEnumerable just being a way to force the compiler to call Enumerable.ElementAt instead of Queryable.ElementAt.

    There may be a better way (e.g. using Take or Skip) though - could you give more information about the bigger picture?

    0 讨论(0)
  • 2021-01-08 01:17

    You can simply mix Skip and First to do the trick:

    mds.Skip(i).First()
    
    0 讨论(0)
提交回复
热议问题