== Why is this an issue?

There's no point in chaining multiple ``++OrderBy++`` calls in a LINQ; only the last one will be reflected in the result because each subsequent call  completely reorders the list. Thus, calling ``++OrderBy++`` multiple times is a performance issue as well, because all of the sorting will be executed, but only the result of the last sort will be kept.


Instead, use ``++ThenBy++`` for each call after the first. 


=== Noncompliant code example

[source,csharp]
----
var x = personList
  .OrderBy(person => person.Age)
  .OrderBy(person => person.Name)  // Noncompliant
  .ToList();  // x is sorted by Name, not sub-sorted
----


=== Compliant solution

[source,csharp]
----
var x = personList
  .OrderBy(person => person.Age)
  .ThenBy(person => person.Name)
  .ToList();
----


ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

=== Message

Use "ThenBy" instead.


'''
== Comments And Links
(visible only on this page)

=== on 30 Jun 2015, 13:51:54 Ann Campbell wrote:
\[~tamas.vajk] I wonder if this is also an efficiency issue. The end result is a list that is sorted only by the last OrderBy argument, but doe all the previous OrderBy's take place, then get thrown away? If so, this would probably be worth adding to the description.

=== on 30 Jun 2015, 13:55:28 Tamas Vajk wrote:
\[~ann.campbell.2] I added a performance related sentence.

=== on 30 Jun 2015, 14:52:39 Ann Campbell wrote:
I shuffled the text some, [~tamas.vajk]

=== on 1 Jul 2015, 06:40:10 Tamas Vajk wrote:
\[~ann.campbell.2] Shouldn't this issue have some performance related label as well?


I simplified the message as the ordering might not happen by some property, but by some complex logic, and in this case we can't display the whole expression and ``++Comparer++`` in the message.

=== on 1 Jul 2015, 11:26:48 Ann Campbell wrote:
added [~tamas.vajk]

endif::env-github,rspecator-view[]
