LINQ Join Error – Join Clause is Incorrect

by David on November 9, 2009

This is a relatively ambiguous error that seems to pop up frequently when first learning LINQ. It took a lot of hunting around on the web to finally come up with an appropriate response to what the issue is. Here’s a link to the article that I found most useful.

http://social.msdn.microsoft.com/Forums/en-US/linqprojectgeneral/thread/bf98ec7a-cb80-4901-8eb2-3aa6636a4fde

Basically, in LINQ, you need to use an anonymous type in order to JOIN b ased on two (or more) columns. Additionally, and where my confusion was, was that you need to “ALIAS” your columns if they are not named the same thing in your two tables (objects).

example LINQ JOIN clause :
…. on new { p.FirstName, p.LastName } equals new { FirstName = q.FName, LastName = q.LName } ….

Note the “=” sign in the above C# example, it is not an “==”. The “=” sign is aliasing the column name!

I hope this helps!

Comments on this entry are closed.

Previous post:

Next post: