Why the GetOrders() does not return any element I get an InvalidOperationException that there are no elements in the sequence.
int maxNumber = GetOrders().Max(o => o.Number);
How can I fix this so I get the integer default value which is 0 when the sequence is empty else I want the max value is the sequence is not empty.
You can use the overload of
Enumerable.DefaultIfEmpty:If you just want to select the
intvalue anyway, this approach is even simpler: