views:

17

answers:

1

Hello.

How can I query RowNumber with Entity Framework? For example:

        var result = data.Users
            .OrderByDescending("Birthday")
            .ThenBy("LastName")
            .ThenBy("FirstName")
            .Select(u =>
                        {
                            RowNumber = ???,
                            u.FirstName,
                            u.LastName
                        });

I want to implement paging for my grid, but I cannot solve problem with finding page with needed user.

I'm using EF4.0. Select method with index(http://msdn.microsoft.com/en-us/vcsharp/aa336758.aspx#SelectIndexed) not works with EF.

May be there is another way to implement this?

+1  A: 

You could use skip, take, or a number of other paging methods supported for LINQ to Entities:

http://msdn.microsoft.com/en-us/library/bb738474.aspx

http://msdn.microsoft.com/en-us/library/bb738702.aspx

For example:

var result = data.Users 
            .OrderByDescending("Birthday") 
            .ThenBy("LastName") 
            .ThenBy("FirstName") 
            .Select(u => 
                        { 
                            u.FirstName, 
                            u.LastName 
                        }).Take(10); 

...would give you the first ten rows. Not sure how efficient that is, but those links may help find the best solution to your individual problem.

Ocelot20