venter venter - 1 year ago 202
C# Question

At least one object must implement IComparable order by

As the title describes an error occurres after using

order by

The order by statment looks like this:

var fahrerGroups = dispoLinien.OrderBy(dl => dl.Linie.GetValidLinienVersionByDate(date).Fahrten.Select(f => f.Beginn)).GroupBy(dl => dl.GetValidDispolinienVersionByDate(date).Fahrer);

Date is always the current date.

I'm trying to order by start time of a service. As far as I found out the error occurres, because my statment returns an object type and object doesn't implement IComparable. The point I didn't understand is that I'm trying to sort a dateTime and not an object type.

Answer Source

Select returns IEnumarable

Maybe, you can select first element to sort your list.

I add FirstOrDefault;

var fahrerGroups = dispoLinien
      .OrderBy(dl => dl
         .Select(f => f.Beginn)
      .GroupBy(dl => dl
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download