Asp.Net MVC - Linq sorting

I have an MVC application that I am almost ending. But I have a situation that cannot understand the syntax.

What I want to do is sort by two columns. When I use the syntax below, it is sorted 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

+3
source share
3 answers

Use .OrderBy (). ThenBy ();

+3
source

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);
}

Read more about the ThenBy statement here .

Good luck

+5
source

Maybe ThenBy?

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

Source: https://habr.com/ru/post/1715092/


All Articles