How do I translate a query that uses ROW_NUMBER() into linq?

c#, linq

Solution

You can write query as beow

var index=1;
var pageIndex=1;
var pageSize = 10;
data.Select(x => new
{
    RowIndex = index++,
    Sno = x.Sno,
    Name = x.Name,
    Age = x.Age
}).OrderBy(x => x.Name)
.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList();

Problem

My table consists of three columns (sno,name,age). I am retrieving this table from the database with extra column (row number) and I used the following code: ``` select * from ( select ROW_NUMBER() over (order by SNo asc)as rowindex,SNo,Name,Age from tblExample) as example where rowindex between ((pageindex*10)+1) and ((pageindex+1)*10) ``` Note, pageindex is the variable that takes some integer value which is passed by the user. My database is Sql Server 2008. I want to write the same query using Linq. How do I do that?

Original source