entity framework not generating second orderby
My problem is that I am trying to make 2 OrderBy
but the second one is never generated for entity framework, I inspected the generated query.
This is what I am trying to do
var query = model.SomeTable.Where(condition);
if (somecondition)
query = query.OrderByDescending(o => o.Table1.Col1).OrderBy(c => c.Table1.Table2.SomeColumn);
var result = query.Select(c => new
{
//selection here
});
Order by for Table1.Table2.SomeColumn
is generated, but the second OrderBy Table1.Col1
is never generated and consequent开发者_C百科ly my results are wrong.
Any ideas?
Use OrderBY and ThenBy Combination.. i.e.:
query = query.OrderByDescending(o => o.Table1.Col1)
.ThenBy(c => c.Table1.Table2.SomeColumn);
精彩评论