Serberuss
Serberuss

Reputation: 2387

The type arguments for method GroupJoin cannot be inferred from the usage

I'm quite new to using Entity Framework and I keep running into this problem where my code can't compile. The error message I get is:

The type arguments for method 'System.Linq.Queryable.GroupJoin(System.Linq.IQueryable, System.Collections.Generic.IEnumerable, System.Linq.Expressions.Expression>, System.Linq.Expressions.Expression>, System.Linq.Expressions.Expression,TResult>>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

I've done some search and found some similar problems but nothing has helped me fix my problem. I'm just trying to output something simple for debugging purposes here is the code I have at the moment:

var result = _context.Set<User>()
             .Where(user => user.GraphMeetingStatistics && user.Id == userId)
             .GroupJoin(_context.Set<Meeting>()
                 .Where(meeting => meeting.UserId == userId),
                 user => user.Id,
                 meeting => meeting.Guid,
                 (user, meeting) => meeting);

I'd appreciate any help with this error

Upvotes: 4

Views: 5291

Answers (1)

Ryan Kohn
Ryan Kohn

Reputation: 13509

As indicated by Thomas Levesque's comment, the keys used to join the collections must be of the same type. So, in your case, user.Id and meeting.Guid are not the same type (int and Guid, respectively). You haven't provided information about the structure of these objects, so I can't tell you exactly how to update your code.

DotNotPerls has a good, basic overview of of how GroupJoin works, and describes the arguments as such:

Arguments 1 and 2:

Argument one is the secondary collection. And argument two is a Func that returns the key from the first object type.

Arguments 3 and 4:

A Func that returns the key from the second object type, and one that stores the grouped object with the group itself.

Upvotes: 7

Related Questions