通过innerjoin访问子表中的所有属性以在asp:GridView上使用

时间:2017-06-17 15:35:47

标签: asp.net entity-framework linq gridview

我编写了这个方法,在asp GridView中将它用作SelectMethod。我想访问子表(EmployeeCourses,EmployeeLanguages,EmployeeSkills)中的所有属性,但我不能在查询中选择y,z,w作为它们的类型不匹配。 我有什么选择?

function doGet(e) {
  var template = HtmlService.createTemplateFromFile('Index');
  if(e.parameter.message === 'true') template.message = 'Hello World!';
  var output = template.evaluate();
  return output;
}

1 个答案:

答案 0 :(得分:0)

您需要创建一个匿名类型或自定义类(DTO)来保存您的投影,在您的情况下应该是DTO因为您想要返回结果,所以您需要定义一个具有4个属性的类来保存这些实体:

public class EmployementDTO
{
  //Define properties here
  public EmployementRequest EmployementRequest{get;set;}
  //..
}

然后:

public List<EmployementDTO> requestsGrid_GetData()
{
    var ukn = new UKN_DBNAMEEntities();
    var query = (from x in ukn.EmployementRequests
        join y in ukn.EmployeeCourses on x.PKEmploymentRequest equals y.FKEmployementRequest
        join z in ukn.EmployeeLanguages on x.PKEmploymentRequest equals z.FKEmploymentRequest
        join w in ukn.EmployeeSkills on x.PKEmploymentRequest equals w.FKEmploymentRequest
        select new EmployementDTO{EmployementRequest=x,EmployeeCourse=y,...);

    return query.ToList();
}