0
我的域模型关联如下:实体框架:访问协会
Project
有许多Task
小号Task
有许多User
小号
取决于User
的状态,我需要更新项目中的一个字段。我的查询如下:
var projects = from project in _data.projects
join task in _data.tasks on project.ProjectID equals task.ProjectID
join user in _data.usersactive on task.TaskID equals user.TaskID
where user.Active == false
select project;
这使我可以得到有用户不活动的项目。
foreach (Project project in projects)
{
bool needUpdate = false;
foreach (Task task in project.tasks)
{
foreach (User user in task.users)
{
// Depending on state of user
// needUpdate = true;
}
}
// If needUpdate = true
// Do something
}
显然这段代码是要找个:
There is already an open DataReader associated with this Connection which must be closed first.
我在MySQL然而,正因为如此我不能够简单地利用MultipleActiveResultSets=True
。
我将如何能够急切地加载这些关联,并让他们可以在foreach
循环中访问?
这竟然是出奇的简单,考虑到微软对预先加载的文件的数量。谢谢! – Laurens
@Laurens哈哈!不客气 :) – gideon