//get full list of active employees
public static object EmployeeList()
{
string traceFile = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
var empList = (from emp in dbViews.EmployeeList
where emp.StatusID == 7
orderby emp.EmpNo
select new
{
emp.id,
emp.Name,
emp.EmpNo,
emp.Telephone,
emp.EmployeeType,
emp.DepartmentName,
emp.Supervisor,
emp.ImmediateSupervisor,
emp.StatusID
});
File.AppendAllText(traceFile, ((ObjectQuery)empList).ToTraceString());
return empList.ToList();
}
执行上述代码时,出现以下错误,不知道为什么
*
无法投射类型为“System.Data.Entity.Infrastructure.DbQuery
1[<>f__AnonymousType0
9 [System.Int32,System.String,System.String,System.String,System.String,System.String,System.String,System.String, System.Nullable`1[System.Int32]]]' 键入'System.Data.Objects.ObjectQuery'。
*
我只想得到上面实体框架代码生成的真正的T-SQL。错误在下面的行
File.AppendAllText(traceFile, ((ObjectQuery)empList).ToTraceString());