tags:

views:

53

answers:

1

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.

+4  A: 

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 }
Timwi
Ah right - boo!!! Nice update and does the trick - cheers Timwi, most appreciated and good explanation as well.
Ricardo Deano