【发布时间】:2012-11-16 23:50:04
【问题描述】:
我有一张员工表和EmployeeCourseStatus 表。
我想显示每个员工的列表以及已完成的课程计数 (status = "CMP")。
我有以下相关子查询导致以下错误:
var query = (from emp in Employee
join adr in EmployeeAddress on emp.id = adr.EmployeeID
select new
{
id = emp.id,
name=emp.name,
country=adr.country,
CompletedCourseCount = (from c in employeeCourseStatus where c.empid = emp.id && c.status == "CMP" select c.id).count()
}
错误:
仅支持 Premitive 类型。
等效的 SQL 子查询是 -
Select emp.id
, emp.name
, adr.Country
, CompletedCourseCount = (select count(id) from EmployeeCourseStatus where id = emp.id and status = "CMP")
from Employee emp
JOIN employeeaddress adr ON adr.EmployeeID = emp.ID
【问题讨论】:
-
Linq to Objects for EF Ver 4.2
-
LINQ to objects 与 EF 无关。什么意思?
-
我的错 - 使用 LINQ to Entities
标签: c# entity-framework linq correlated-subquery