我在写一个应用程序,我需要一个特定的学生EvaluationRounds
。加载相关实体多个分支和多个级别
一切都从项目开始。一个项目有很多组。一个小组有很多成员,但是一个小组也可以有很多小组成员。这是通过关联表完成ProjectGroupMembers
另一方面,一个项目有很多评估轮。
目前我有这个LINQ声明:
from r in _context.EvaluationRounds.Include(e => e.EvaluationRoundProject.ProjectGroups.Select(pg => pg.Persons))
.Include(e => e.Evaluations)
join g in _context.ProjectGroups on r.ProjectId equals g.ProjectId
join m in _context.ProjectGroupMembers on g.ProjectGroupId equals m.GroupId
where m.PersonId == studentId && r.EvaluationRoundStartTime < DateTime.Now && r.EvaluationRoundEndTime > DateTime.Now
select r
我们使用using语句来当我们都榜上有名处置的DbContext的。
问题是EvaluationRoundProject
及其亲属没有加载EvaluationRounds
。这就是我们得到:
'((System.Data.Entity.DynamicProxies.EvaluationRound_7400F2ED13550F1E92655A802808E4B94D454A30979C80D0EEED31D0CB7D7005)(新System.Collections.Generic.Mscorlib_CollectionDebugView(activeEvaluationrounds).Items [0]))EvaluationRoundProject' 抛出
from r in _context.EvaluationRounds.Include("EvaluationRoundProject").Include(e => e.EvaluationRoundProject.ProjectGroups.Select(pg => pg.Persons)).Include(e => e.Evaluations) join g in _context.ProjectGroups on r.ProjectId equals g.ProjectId join m in _context.ProjectGroupMembers on g.ProjectGroupId equals m.GroupId where m.PersonId == studentId && r.EvaluationRoundStartTime < DateTime.Now && r.EvaluationRoundEndTime > DateTime.Now select r
也
:
我已经试过型 'System.ObjectDisposedException' 的例外
from r in _context.EvaluationRounds.Include(a => a.EvaluationRoundProject).Include(e => e.EvaluationRoundProject.ProjectGroups.Select(pg => pg.Persons)).Include(e => e.Evaluations)
join g in _context.ProjectGroups on r.ProjectId equals g.ProjectId
join m in _context.ProjectGroupMembers on g.ProjectGroupId equals m.GroupId
where m.PersonId == studentId && r.EvaluationRoundStartTime < DateTime.Now && r.EvaluationRoundEndTime > DateTime.Now
select r
编辑:评价还没有装入evaluationround
EDIT2:这是使用代码
using (_context = new PeerEvaluationContext())
{
var activeEvaluationrounds = from r in _context.EvaluationRounds.Include(e => e.EvaluationRoundProject.ProjectGroups.Select(pg => pg.Persons)).Include(e => e.Evaluations)
join g in _context.ProjectGroups on r.ProjectId equals g.ProjectId
join m in _context.ProjectGroupMembers on g.ProjectGroupId equals m.GroupId
where m.PersonId == studentId && r.EvaluationRoundStartTime < DateTime.Now && r.EvaluationRoundEndTime > DateTime.Now
select r;
return activeEvaluationrounds.ToList();
}
编辑3全:这个问题是由于懒惰正在使用加载。但我在网上寻找,他们说include
部分会照顾到这一点。
use .ToList()? –
已经这样做了,将这些信息添加到问题 – freshrebel