实体框架-在where语句中查询

时间:2019-01-28 09:16:32

标签: entity-framework asp.net-mvc-4

我有一个需要从表中获取字符串值列表的场景。

我需要查询Subject表并获取主题列表:

EmployeeDetails emp = new EmployeeDetails();
emp.subjects = from x in EmpDB.subjects
                join y in EmpDB.employeeInfo 
                 on x.subjectCode equals y.subjectCode select new
   {
    x.subjectTitle,
   }.toList();

我有一个员工ID,我需要查询EmployeeDetails表并获取特定SubjectCodes的{​​{1}},并且使用这些主题代码,我需要查询{{1 }}表并获取主题值。

1 个答案:

答案 0 :(得分:0)

我假定在EmployeeDetails类中,您具有带有“列表”的“主题”。

EmployeeDetails emp = new EmployeeDetails();
emp.subjects = (from x in EmpDB.subjects
                join y in EmpDB.employeeInfo on x.subjectCode equals y.subjectCode
                where y.EmployeeId = <<your ID>>  // Employee ID you searching 
                  select x.subjectTitle).ToList();