Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

linq

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.

like image 911
Ricardo Deano Avatar asked Sep 22 '10 12:09

Ricardo Deano


1 Answers

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 }
like image 143
Timwi Avatar answered Sep 27 '22 17:09

Timwi