Luca Romagnoli Luca Romagnoli - 6 months ago 44
C# Question

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

I'm using the method

to get a specific element of a query's result.

var mds = db.TDP_MissioniDestinazioni.Where(p => p.MissioneID == missioneRow.MissioneID);

destinazioneRow = mds.ElementAt(i);

LINQ to Entities does not recognize the method

Int32)' method, and this method cannot be translated into a store

Why am I getting this error and how can I fix it?

Answer Source

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?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download