2
    //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__AnonymousType09[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」と入力します。

*

上記の Entity Framework コードによって生成された実際の T-SQL を取得したいだけです。エラーは以下の行にあります

File.AppendAllText(traceFile, ((ObjectQuery)empList).ToTraceString());
4

1 に答える 1

3

DbContext APIを使用しているため、。だけを使用できますempList.ToString()

于 2013-02-12T09:31:27.677 に答える