created a sample code for doing the same. Assuming join clause has to be applied on same columns for each extra available table.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace JoinMoreThanTwoTablesDynamically
{
class Program
{
static void Main(string[] args)
{
List<list><int>> dataset = new List<list><int>> {
new List<int>{1,2,5,6},
new List<int>{1,3,5,6},
new List<int>{4,5,6},
new List<int>{1,5}
};
var q1 = from d1 in dataset[0]
join d2 in dataset[1]
on d1 equals d2
select d1;
int noOfTables = dataset.Count;
if (noOfTables > 2)
{
for (int i = 2; i < noOfTables; i++)
{
q1 = from newd1 in q1
join d3 in dataset[i]
on newd1 equals d3
select newd1;
}
}
foreach (var item in q1)
{
Console.WriteLine(item.ToString());
}
}
}
}
Hope this will help !! Happy Programming !!