When i don't use ToList() method to query firsQue everything is "Ok!" but i need execute firsQue immediately! Then i added to the end ToList() method and got exception in second query secQue "at least one object must implement IComparable".
I dont understand that caused it, grouping performs by g.Action.ActionType.Name... It's string, string type implements IComparer interface
static void Main(string[] args)
{
    var firsQue  = GetAll()
        .SelectMany(s => s.Goals
            .Where(s2 => s2.ID == 2)
             .SelectMany(f => f.Actions
                 .SelectMany(h => h.GoalProgresses))).ToList();
    var secQue = (from g in firsQue  
                        group g by g.Action.ActionType.Name into a
                        select new
                        {
                            Name = a.Key,
                            Duration = a.Sum(s => s.Action.Duration),
                            Done = a.Sum(s => s.DurationComplete),
                            RemainsToDo = (a.Sum(s => s.Action.Duration) - a.Sum(s => s.DurationComplete))
                        })
                         .OrderBy(s => s)
                         .ToList();
    System.Console.ReadLine();
}
static IQueryable<Patient> GetAll()
{
    return db.Patients;
}
}
The problem is here:
.OrderBy(s => s)
Compiler doesn't know how to compare your values and perform the ordering.Your type must implement IComparable (though it's anonymous type) or you can make your sort by some property:
.OrderBy(s => s.ID)
You are calling OrderBy but your expression s => s is just yielding the anonymous type created in the select new above. Anonymous types are not comparable, so you can't order by them. Maybe you mean .OrderBy(s => s.Name)?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With