Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi!
i have 4tables 1.organization 2.department 3.location 4. participant
1.organization have the fields a. org_id(PK) b. name
2.department have the fields a. dept_id(PK) b. name
3.location have the fields a. loc_id(PK) b. name
4. participant have the fields a. participant_id (pk) b)name c)org_id d) dept_id e)loc_id

i want to show grid view with the following fields.
1. participant_name 2. org_name 3.location_name 4. department_name

please tell the linq query for asp.net that show the above fields.
Posted
Updated 31-Dec-13 19:44pm
v2

1 solution

C#
using System.Collections.Generic;
using System.Linq;
class program
{
    static void Main(string[] args)
    {
        List<organization> lstOrg = new List<organization>();
        List<department> lstDep = new List<department>();
        List<location> lstLoca = new List<location>();
        List<participant> lstPartip = new List<participant>();


         var data =   lstPartip.Join(lstOrg, (k => k.org_id), (k => k.org_id), (p, o) => new { p, o })
            .Join(lstDep, (k => k.p.dep_id), (k => k.dep_id), (po, d) => new { po, d })
            .Join(lstLoca, (k => k.po.p.loc_id), (k => k.loc_id), (pod, l) => new { pod, l })
            .Select(k => new {
                participant_name =  k.pod.po.p.par_name
                ,org_name = k.pod.po.o.org_name
                ,location_name =k.l.loc_name
                ,department_name = k.pod.d.dep_name
            
            }).ToList();

      grid.datasource = data;
      grid.databind();       
         
    }
}

public class organization
{
    public int org_id { get; set; }
    public string org_name { get; set; }
}
public class department
{
    public int dep_id { get; set; }
    public string dep_name { get; set; }

}
public class location
{
    public int loc_id { get; set; }
    public string loc_name { get; set; }

}
public class participant
{
    public int par_id { get; set; }
    public string par_name { get; set; }
    public int org_id { get; set; }
    public int dep_id { get; set; }
    public int loc_id { get; set; }
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900