2012-04-12 144 views
-6

我有4個名單,我需要聯合起來LINQ的加入4名單<T>

public class Person 
{ 
    public int personid { get; set; } 
    public string fname { get; set; } 
    public string lname { get; set; } 
} 

public class Department 
{ 
    public int depid { get; set; } 
    public 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<Person> Persons=GetPersons(); 
List<Department> departmentlist=getDepartments(); 
List<Group> grouplist=getgroups(); 
List<UploadFile> filelist=getFiles(); 

我需要一個像輸出:

 
fileid fname  filename path       

1  samplename Mydoc  departmentname+">"+groupname 
+0

如果這些get函數來自同一個數據庫,我建議使用Linq2SQL或實體框架進行連接,而不是使用in內存。 – Magnus 2012-04-12 08:55:18

+2

我們沒有爲你做功課。向我們展示您的代碼,解釋您遇到的問題,然後我們可以爲您提供幫助。 – 2012-04-12 08:55:23

回答

1

你可以使用Zip

List persons=GetPersons(); 
List departmentlist=getDepartments(); 
List grouplist=getgroups(); 
List filelist=getFiles(); 

var result = persons.Zip(departmentlist, (person, department) => person.fname + " " + department.departmentname) 
        .Zip(grouplist, (personAndDepartment, group) => personAndDepartment + " " + group.groupName); 

// etc ...