Linq加入4个列表<t> </t>

时间:2012-04-12 08:46:31

标签: c# linq list join

我有4个需要加入的列表

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

1 个答案:

答案 0 :(得分: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 ...