views:

155

answers:

3

I have a MVC application that I'm near completing. But I have a situation that cannot figure out the syntax for.

What I want to do is to sort on two columns When I use the syntax below, it sorts by one column, then the next.

        public IQueryable<vw_FormIndex> FindAllFormsVw(int companyIdParam)
    {
        return _db.vw_FormIndexes.Where(d => d.companyID == companyIdParam).OrderBy(d => d.formSortOrder).OrderBy(d => d.formCustNumber);
    }

Suggestions Please

+5  A: 

I think you want ThenBy

public IQueryable<vw_FormIndex> FindAllFormsVw(int companyIdParam)
{
    return _db.vw_FormIndexes.Where(d => d.companyID == companyIdParam).OrderBy(d => d.formSortOrder).ThenBy(d => d.formCustNumber);
}

More on ThenBy operator here.

Good luck!

thinkzig
+2  A: 

Use .OrderBy().ThenBy();

Craig Stuntz
A: 

Maybe ThenBy?

_db.vw_FormIndexes.Where(d => d.companyID == companyIdParam).OrderBy(d => d.formSortOrder).ThenBy(d => d.formCustNumber);
orip