tags:

views:

9849

answers:

4

i have table movies and categories, i what get ordered list by categoryID first and then by Name

movie table has columns: ID, Name, CategoryID category table has: ID, Name

tried something like this but doesnt work:

var movies=_db.Movies.OrderBy(m=>{ m.CategoryID, m.Name })
+116  A: 

This should work for you:

Var movies = _db.Movies.Orderby(c => c.Category).ThenBy(n => n.Name)
Nathan W
LOL :), thanks alot
msony
Here. Have an upvote my good sir. Solved it for me.
Maxim
A: 

include System.Linq; :)

Mega
convert to comment
Midhat
+13  A: 

Using non-lambda, query-syntax LINQ, you can do this:

var movies = from row in _db.Movies 
             orderby row.Category, row.Name
             select row;
Scott Stafford
I added this answer nearly two years after the original answer was accepted, cause I wanted the non-lambda one and figured others would too. I wonder if my vote count will ever catch up to the original...
Scott Stafford
@Scott thanks for adding that, it certainly helped me out :)
Colin O'Dell
A: 

great simple answer Scott Stafford, thanks

Federico Vargas