9

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.

1 Answer 1

18

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 }
1
  • Ah right - boo!!! Nice update and does the trick - cheers Timwi, most appreciated and good explanation as well. Sep 22, 2010 at 12:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.