我有使用下面的代碼Student
表的主鍵:無法檢索上下文中的foreach循環跟蹤實體
var stud_id = (from p in context.Students
where p.Student_Name == "Bruce"
select p.Student_Id);
當我嘗試使用stud_id
檢索整個實體,用下面的代碼:
Student requiredstud = new Student();
foreach (var p in stud_id)
{
//Console.WriteLine(p);
requiredObj = context.Students.Find(p);
string tempObj = JsonSerializer.SerializeToString<Student>(requiredObj);
Console.WriteLine(tempObj);
}
它給就行了以下異常:
requiredObj = context.Students.Find(p);
如何解決這個問題,並獲取student
編輯的詳細信息: 的InnerException
是:{"There is already an open DataReader associated with this Command which must be closed first."}
點擊'查看詳情...',看到了內部異常,你可以把它添加到你的問題 – Habib
@Habib:新增的InnerException爲 –