Code First IndexOf? RRS feed

  • Question

  • Hello All,

    Is there a way to get the index of an item in a query, server-side?

    Thank you,


    Friday, April 8, 2011 12:17 PM


  • Hello,

    simple answer is no. Linq to entities dosn't support Select overload which is able to use index. Index on server side is for example in SQL server provided by ROWNUMBER and PARTITON BY function. This approach is only used if query contains OrderBy, Skip and Take. You can use this approach to compute index on client side:

    var query = context.MyEntities
            .OrderBy(e => e.Date)
            .Select((e, i) => new
               Index = i,
               Entity = e

    Same will work with Skip and Take but you will have to compute the real index in whole sequence.

    Best regards,

    • Marked as answer by Jackie-Sun Wednesday, April 20, 2011 5:33 AM
    Monday, April 11, 2011 7:19 AM