Please see image:
I am trying to create a LINQ query that combines 5 different tables on 1 to 3 different columns. I am basically taking the examples of 2 tables and repeating the join sections for tables 3 through 5.
UPDATE: how do I get the following LINQ query to work?????
var match = (from t1 in context.cKNA1
join t2 in context.cKNB1 on
new { t1.KUNNR, t1.RowId } equals
new { t2.KUNNR, t2.RowId }
join t3 in context.cKNVV on
new { t2.KUNNR, t2.RowId } equals
new { t3.KUNNR, t3.RowId }
join t4 in context.cKNVH on
new { t3.KUNNR, t3.RowId } equals
new { t4.KUNNR, t4.RowId }
SELECT ....columns here....)
I can't find anything online where there are more than 3 tables *AND 2 or more columns.
Write this query:
var match = from t1 in context.cKNA1
join t2 in context.cKNB1 on
new { t1.KUNNR, t1.RowId } equals
new { t2.KUNNR, t2.RowId }
join t3 in context.cKNVV on
new { t2.KUNNR, t2.RowId } equals
new { t3.KUNNR, t3.RowId }
join t4 in context.cKNVH on
new { t3.KUNNR, t3.RowId } equals
new { t4.KUNNR, t4.RowId }
SELECT t1.KUNNR;
In fact, just remove the parenthesis. If it still doesn't work, the visual studio will mark one of those join
words as error. If so, it means that the columns you are trying to link, have different data types.
Suppose that the VS mark the first join
word as error. So, it means that t1.KUNNR
and t2.KUNNR
have different data types, or t1.RowId
and t2.RowId
have different data types.
Check and correct your data types, the problem will go away.