C# Joining 3 Lists with Linq -
i want join 3 lists have following format:
list1: countryid | countrydata | regionuid =================================== 12 | has gras | 4567 12 | nice weather | 6789 16 | stormy weather | 1234 list2: countryid | countryname ======================= 12 | green hill 16 | stormy mountain list3: regionuid | regionname ======================= 4567 | above 1000feet 6789 | on ground 1234 | on hill output should like:
countryname | countrydata | regionname ============================================== green hill | has gras | above 1000feet green hill | nice weather | on ground stormy mountain | stormy weather | on hill where region unique , country can fit multiple lines
you want this:
var list1 = new []{ new { countryid = 12, countrydata = "has 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 ground"}, new {regionuid = 1234, regionname = "on hill"} }; var result = m1 in list1 join m2 in list2 on m1.countryid equals m2.countryid select new { m2.countryname, m1.countrydata, m1.regionuid } intermediate join m3 in list3 on intermediate.regionuid equals m3.regionuid select new { intermediate.countryname, intermediate.countrydata, m3.regionname}; rw
Comments
Post a Comment