2017-12-27 21 views
0

특정 학생과 EvaluationRounds이 필요한 곳에 응용 프로그램을 작성하고 있습니다.관련 엔터티 여러 지점 및 여러 수준로드

모든 것이 프로젝트로 시작됩니다. 프로젝트에는 많은 그룹이 있습니다. 그룹에는 많은 구성원이 있지만, 한 구성원도 여러 그룹에 속할 수 있습니다. 이것은 연관 테이블 ProjectGroupMembers에 의해 수행됩니다. 반면에 프로젝트에는 많은 평가 라운드가 있습니다.

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 

우리는 즉시 우리가 목록을 가지고로 dbcontext 처분 using 문을 사용

현재 나는이 LINQ 문이있다.

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 

편집 :이 코드

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를 사용하여 전체입니다 : :이 평가는 또한 evaluationround

Edit2가에로드되지 않습니다이 문제는 게으른 때문에 발생 적재가 사용됩니다. 그러나 나는 인터넷을 보러 갔다. 그리고 그들은 그들이 include 일부가 이것을 처리 할 것이다라고 말했다.

+0

.ToList()? –

+0

이미 그 질문에 대답을 추가 정보를 – freshrebel

답변

0

지연로드로 인해 오류가 발생했다고 생각됩니다. EvaluationRound 또는 EvaluationRoundProject 엔티티는 virtual이고 EF는 _context이 이미 삭제 된 후 어딘가에 데이터를로드하려고 시도하는 탐색 속성을가집니다. 따라서 다른 클래스를 사용하여 쿼리를 선택하려고합니까?

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 new EvaluationRoundDto 
    { 
     EvaluationRoundId = r.EvaluationRoundId, 
     ProjectId = r.ProjectId 
     //etc. 
    }; 

난 당신이 virtual 탐색 속성을 확인해야한다고 생각하고 컨텍스트가 이미 배치 된 후가 사용되는 경우.

+0

주셔서 감사합니다. 대부분의 경우 우리는 평가가 필요하지만 프로젝트는 필요하지 않기 때문에 게으른로드가 실제로 사용됩니다. 나는이 솔루션을 시도 할 것이지만, 여기 [link] (https://msdn.microsoft.com/en-us/library/jj574232(v=11113).aspx)와 같은 곳에서는 '포함 된 부분 '프로젝트를 평가판에로드하여 액세스 할 수 있습니다. 그래서 나는 이것이 충분하다고 생각했다. 왜 그렇지 않은가? – freshrebel

+0

나는 이것을 시도하고'System.NotSupportedException : '엔티티 또는 복합 유형'AP.PeerEvaluations.DAL.Contexts.EvaluationRound '를 LINQ to Entities 쿼리에서 생성 할 수 없다.'' – freshrebel

+0

'새 EvaluationRoundDto 선택'과 같은 검색어를 선택하려면 새 수업을 만들어야합니다. 엔티티 클래스를 사용하지 않습니다. – lucky