Asp.net Join创建重复项

时间:2019-11-07 04:12:47

标签: asp.net asp.net-mvc join asp.net-web-api

我有以下代码来显示来自多个表的员工记录,但是当我尝试显示员工语言时,我多次获得相同的记录。

例如:如果一名员工说3种语言,则我会得到3次相同的记录,并且在每条记录上都会显示每种语言。

  

我如何更新联接以合并它,以便一位员工记录并   多种语言?

 public IHttpActionResult GetEmployees()
 {
         var query = (from emp in db.employees /*where ToInt32(emp.active) =1*/
         join location in db.locations on emp.location_id equals location.id into emp_loc
         from  location in emp_loc.DefaultIfEmpty()    
         where emp.active.Equals(1)

         join mail in db.mail_station on emp.mail_station_id equals mail.id
         into emp_mail
         from mail in emp_mail.DefaultIfEmpty()
         join mgr in db.employees on emp.supervisor_emp_id equals mgr.id
         into emp_supervisor
         from mgr in emp_supervisor.DefaultIfEmpty()

// below 
         join emplang in db.Employee_Languages on emp.id equals emplang.Employee_id
         into emp_emplang
         from emplang in emp_emplang.DefaultIfEmpty()
         join lang in db.Languages on emplang.Languages_id equals lang.id
         into emp_lang
         from lang in emp_lang.DefaultIfEmpty()
         select new
            {
             emp.employee_number,
             emp.employee_photo,
             emp.first_name,
             emp.supervisor_emp_id,
             emp.Teams,
             mail.code,
             mail.name,
             ManagerFirstName = mgr.first_name,
             lang.Language1,
             emplang.Verbal_Proficiency,
             emplang.Written_Proficiency,
             emplang.Certification_Location,

      });
      var employees = query.ToList();
      return Ok(employees);

 }

在“员工详细信息”视图中,我试图显示语言信息,如下所示

   <table id="myTable" class="table table-striped table-bordered" datatable="ng" dt-options="vm.dtOptions" dt-instance="vm.dtInstance" width="100%" dt-column-defs="vm.dtColumnDefs">
     <tr>
      <td><strong>Language:</strong></td>
      <td><strong>Verbal Proficiency:</strong></td>
      <td><strong>Written Proficiency:</strong></td>
      <td><strong>Certification Location:</strong></td>
     </tr>
     <tr>
      <td>{{Getemployee.Language1}}</td>// list of all langauage english, spanish, arabic,....
      <td>{{Getemployee.Verbal_Proficiency}}</td>
      <td>{{Getemployee.Written_Proficiency}}</td>
      <td>{{Getemployee.Certification_Location}}</td>
     </tr>
    </table>

但是我得到了重复的信息,如果员工说两种语言,我会得到两次相同的记录,但只显示一种语言,

我想在同一条记录上查看所有语言信息

0 个答案:

没有答案