photo_tom
photo_tom

Reputation: 7342

Asp.Net MVC - Linq Sorting Question

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

Upvotes: 3

Views: 1832

Answers (3)

orip
orip

Reputation: 75557

Maybe ThenBy?

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

Upvotes: 0

Craig Stuntz
Craig Stuntz

Reputation: 126587

Use .OrderBy().ThenBy();

Upvotes: 3

JamieGaines
JamieGaines

Reputation: 2082

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!

Upvotes: 5

Related Questions