i have 4 list that I need to join together
public class Person
{
public int personid { get; set; }
public string fname { get; set; }
public string lname { get; set; }
}
public class Department
{
int depid { get; set; }
string departmentname { get; set; }
}
public class Group
{
public int groupid { get; set; }
public int depid { get; set; }
public string groupname { get; set; }
}
public class UploadFile
{
public int fileid { get; set; }
public int personid { get; set; }
public int groupid{ get; set; }
public string filename { get; set; }
}
List
List
List
List
I need an output like:
fileid fname lname filename path
1 Jon ... ... departmentname+">"+groupname
thanks!


VulpesRank #55 · 29.2K reputationPosted Apr 12, 2012, 1:26 AM EDT
SenthilkumarRank #387 · 6.5K reputationPosted Apr 12, 2012, 12:48 AM EDT
You need to join by the key fields.
join D in Departmentlist on D.depid equals G.depid
join G in Grouplist on G.groupid equals U.groupid
join U in Filelist U.personid equals P.personid
select new { U.fileid,P.fname,P.lname, path = U.filename + ">" + U.Path };
The query will have the joined table results.
Now you can iterate the results.
// Display joined groups.
foreach (var group in query)
{
Console.WriteLine(group.fileid+" "+ group.fname+" "+group.lname+" "+group.path);
}
Hope this will help you.
Ajay Patel148 reputationPosted May 11, 2012, 4:23 AM EDT
http://ajaypatelfromsanthal.blogspot.in/2012/05/joins-in-linq.html