How do I inner join multiple columns from the same tables via Linq?
For example: I already have this...
join c in db.table2 on table2.ID equals table1.ID
I need to add this...
join d in db.table2 on table2.Country equals table1.Country
How do I inner join multiple columns from the same tables via Linq?
For example: I already have this...
join c in db.table2 on table2.ID equals table1.ID
I need to add this...
join d in db.table2 on table2.Country equals table1.Country
This is applicable for any kind of datatype.
from http://www.onedotnetway.com/linq-to-sql-join-on-multiple-conditions/
Both these tables have PostCode and CouncilCode as common fields. Lets say that we want to retrieve all records from ShoppingMall where both PostCode and CouncilCode on House match. This requires us to do a join using two columns. In LINQ such a join can be done using anonymous types. Here is an example.
In VB:
This is the only way I was able to get it to work (in c#).
You can put your query inside a Where clause instead of using the join operator.
The join operator supports multiple clauses in VB.NET, but not C#.
Alternatively, you can use the ANSI-82 style of 'SQL' syntax, e.g.: