Data Browser - Viewing Site  Sector 23 Code Bank Logged in as:  Guest  


LINQ - Join problems
The following applies to the LINQ May 2006 CTP

Problem: Linq inner join failed:
Cause: the on clause had the joined tables in order from "join to" to "join from".
Solution: reverse the order of the fields in the on clause, so order is as follows:
"from TBL1 join TBL2 ON TBL1.ID equals TBL2.ID"
(NOT "TBL2.ID equals TBL1.ID").

Problem: Linq outer join failed: (index out of range/DefaultIfEmpty is not supported).
Cause: the select results did not select anything from the joined table.
Solution: Change select clause from:
"Select TBL1" (incorrect) to:
"Select new {TBL1, TBL_OuterJoined}" (or select any combination of fields, etc, as long as the outer joined table has 1 or more fields returned.)

Both of these seem like bugs that will likely be fixed in a future release, especially the 2nd one. I can't imagine them being desirable behavior.

Issue 1:
I believe this is fixed, but I haven't dared try it.
Issue 2:
Now, it will break if you do it using the hack I outlined above. Instead, do NOT reference the outer joined table directly in the select clause, or it will treat the outer join as an INNER join.

If you must select fields from the outer joined table, the proper way to reference an outer joined table now is to select it as a subquery in the select clause. Do not use the 'into' clause anymore, unless you really need to.

Created By: amos 9/18/2007 11:07:15 AM
Updated: 10/12/2007 4:44:35 PM