LINQ to object : How to perform 3 join between 3 List<T>

  • Thread starter Thread starter Sudip_inn
  • Start date Start date
S

Sudip_inn

Guest
suppose i have List1, List2 & List3

now i want to perform left join between List1 & List2 and equi join between List1 & List3 at same place. how to achieve it....if possible please include a sample code.

this kind of join i am looking for

var list1 = new []{
new { CountryID = 12, CountryData = "Has good gras", regionUID = 4567 },
new { CountryID = 12, CountryData = "nice weather", regionUID = 6789 },
new { CountryID = 16, CountryData = "stormy weather", regionUID = 1234 }};

var list2 = new []{
new { CountryID = 12, CountryName = "green hill"},
new { CountryID = 16, CountryName = "stormy mountain"}
};

var list3 = new []{
new {regionUID = 4567, regionName = "above 1000feet"},
new {regionUID = 6789, regionName = "on the ground"},
new {regionUID = 1234, regionName = "on the hill"}
};

var result = from m1 in list1
join m2 in list2 on m1.CountryID equals m2.CountryID
select new { m2.CountryName, m1.CountryData, m1.regionUID } into intermediate
join m3 in list3 on intermediate.regionUID equals m3.regionUID
select new { intermediate.CountryName, intermediate.CountryData, m3.regionName};



but the above code does not suit for my scenario. so include a sample code where left join between List1 & List2 and equi join between List1 & List3 at same place.

thanks

Continue reading...
 
Back
Top