MyDaftQuestions
MyDaftQuestions

Reputation: 4701

The key selector type for the call to the 'GroupBy' method is not comparable in the underlying store provider

I'm struggling with the below query, using Entity Framework (v4).

I already have an IQueryable<T> object called _myTable. I'm now trying to add some filtering.

MyTable (as a table) is part of relationship, and joins to another table called MyCompany, which in turns is a one to many to another tabled called MyPeople. Within MyPeople is a date column, and I'm trying to filter between a Min() and Max() (person started/left company).

My code is

this._myTable = from v in this._myTable
             group v by v.MyCompany.MyPeople into grouped
             where EntityFunctions.DiffDays(grouped.Min(s => s.DateTime), grouped.Max(s => s.DateTime)) > 0
             select grouped.FirstOrDefault();

The program runs but when I inspect the results I see an exception has been thrown.

"The key selector type for the call to the 'GroupBy' method is not comparable in the underlying store provider."

I've tried to understand the answer but I can't - I can read what it says, I understand that the selector type is not comparable, but I don't understand how I can fix it!

Upvotes: 0

Views: 4342

Answers (1)

xanatos
xanatos

Reputation: 111940

The v.MyCompany.MyPeople is probably a reference to another table (MyPeople). Try changing it to v.MyCompany.MyPeople.Id (or whatever the name of the primary key of MyPeople is.)

Upvotes: 2

Related Questions