Ricardo Deano
Ricardo Deano

Reputation: 2819

The type of one of the expressions in the join clause is incorrect when the types are the same

This has confused me, I have the title error on the join in the following LINQ:

var r = (from k in location.tblKeyAccountInfoes
                     join l in location.tblLocations
                     on new { k.MemberID, k.LocationID } equals
                     new {l.MemberId, l.LocationId }
                     where k.MemberID == memberid && k.UserName == username
                     select l.LocationName);

            return r.ToString();

However, the type for MemberId and LocationId is the same so I'm not sure what I have done wrong.

Any pointers gratefully received.

Upvotes: 9

Views: 6682

Answers (1)

Timwi
Timwi

Reputation: 66573

The types of MemberID and LocationID may be the same, but they have to have the same name as well.

In your example, one of them has ID (capital D) and the other has Id (lower-case d). That is enough to make the anonymous types separate types.

You can fix this by specifying names explicitly, for example:

 join l in location.tblLocations
 on new { k.MemberID, k.LocationID } equals
 new { MemberID = l.MemberId, LocationID = l.LocationId }

Upvotes: 18

Related Questions