2011-08-31 1 views
2

엔티티에 linq를 잘 수행하는 데 문제가 있습니다. 내가 가진 쿼리 (내 코드가 아닌 다른 사람 코드 유지 :-))에는이 쿼리의 결과를 사용하는 WPF 화면에 필요한 모든 항목이 포함되어 있습니다.Linq to Entities 많은 컬럼에서 성능 문제가 발생했습니다.

이제 생성 된 SQL은 매우 빠르게 실행되고 한 행의 데이터 만 반환합니다. 하지만 그것은 570 열을 반환하고, 나는 모든 개체와 모든 필드를 만드는 오버 헤드에 성능이 있다고 생각합니다.

지연로드를 사용해 보았지만 성능에 아무런 영향을 미치지 않습니다.

필자는 불필요한 "include"문을 제거하려고 시도했지만 모두 필요하다고 생각됩니다. 여기

는 LINQ 쿼리입니다 :

var myQuery = 
       from appt in ctx.Appointments 
           .Include("ScheduleColumnProfile") 
           .Include("EncounterReason") 
           .Include("Visit") 
           .Include("Visit.Patient") 
           .Include("Visit.Patient.PatientInsurances") 
           .Include("Visit.Patient.PatientInsurances.InsuranceType") 
           .Include("Visit.Patient.PatientInsurances.InsuranceCarrier") 
           .Include("MasterLookup") 
           .Include("User1") 
           .Include("User2") 
           .Include("Site") 
           .Include("Visit.Patient_CoPay") 
           .Include("Visit.Patient_CoPay.User") 
           .Include("Visit.VisitInstructions.InstructionSheet") 
        where appt.VisitId == visitId 
         && appt.MasterLookup.LookupDescription.ToUpper() != Rescheduled 
         && appt.Site.PracticeID == practiceId 
         && appt.MasterLookup.LookupDescription.ToUpper() != Cancelled 
        orderby appt.AppointmentId descending 
        select appt; 

는 SQL은 570 선택 한 Statment의 열 및 3 또는 4 연합 ALLS 4000 선 길이 생성, 그래서 나는 정말 누군가가 여기에 붙여 넣기하지 않을거야 그것을보고 싶어. 기본적으로 가능한 경우 노동 조합을 제거 할 수있는 방법을 찾고 있으며 필요한 부분 만 열을 정리합니다.

도움말!

:-)

+0

: http://stackoverflow.com/questions/5521749/how-many-include-i-can-use-on-objectset-in-entityframework-to-retain-performance/5522195#5522195 –

+0

감사합니다. 사용법이 미치는 영향을 설명하는 데 도움이됩니다. 포함. 그러면 솔루션은 objectContext.LoadProperty()를 사용합니까? – Scot

+0

이 솔루션은 여러 기술을 사용하여 시나리오에서 최상의 성능을 제공하는 것입니다. –

답변

2

누군가가 계속 추적한다면이 솔루션이 나를 위해 작동하게됩니다. 댓글을 달고 제안을 한 모든 사람들에게 감사드립니다 ... 결국 내가 아래에있는 것에 나를 안내하게되었습니다.

  ctx.ContextOptions.LazyLoadingEnabled = true; 

      var myQuery = 
       from appt in ctx.Appointments 
       where appt.VisitId == visitId 
        && appt.MasterLookup.LookupDescription.ToUpper() != Rescheduled 
        && appt.Site.PracticeID == practiceId 
        && appt.MasterLookup.LookupDescription.ToUpper() != Cancelled 
       orderby appt.AppointmentId descending 
       select appt; 


      var myAppt = myQuery.FirstOrDefault(); 

      ctx.LoadProperty(myAppt, a => a.EncounterReason); 
      ctx.LoadProperty(myAppt, a => a.ScheduleColumnProfile); 
      ctx.LoadProperty(myAppt, a => a.Visit); 
      ctx.LoadProperty(myAppt, a => a.MasterLookup); 
      ctx.LoadProperty(myAppt, a => a.User1); 
      ctx.LoadProperty(myAppt, a => a.User2); 
      ctx.LoadProperty(myAppt, a => a.PatientReferredProvider); 

      var myVisit = myAppt.Visit; 

      ctx.LoadProperty(myVisit, v => v.Patient); 
      ctx.LoadProperty(myVisit, v => v.Patient_CoPay); 
      ctx.LoadProperty(myVisit, v => v.VisitInstructions); 
      ctx.LoadProperty(myVisit, v => v.EligibilityChecks); 

      var pat = myVisit.Patient; 

      ctx.LoadProperty(pat, p => p.PatientInsurances); 


      //load child insurances 
      foreach (PatientInsurance patIns in myAppt.Visit.Patient.PatientInsurances) 
      { 
       ctx.LoadProperty(patIns, p => p.InsuranceType); 
       ctx.LoadProperty(patIns, p => p.InsuranceCarrier); 
      } 

      //load child instruction sheets 
      foreach (VisitInstruction vi in myAppt.Visit.VisitInstructions) 
      { 
       ctx.LoadProperty(vi, i => i.InstructionSheet); 
      } 

      //load child copays 
      foreach (Patient_CoPay coPay in myAppt.Visit.Patient_CoPay) 
      { 
       ctx.LoadProperty(coPay, c => c.User); 
      } 

      //load child eligibility checks 
      foreach (EligibilityCheck ec in myAppt.Visit.EligibilityChecks) 
      { 
       ctx.LoadProperty(ec, e => ec.MasterLookup); 
       ctx.LoadProperty(ec, e => ec.EligibilityResponse); 
      } 
여기 읽기
0

내가 표시해야 할 속성을 포함하는 새 클래스를 만드는 것이 좋습니다. 새로운 유형으로 프로젝트를 만들 때 Include 문은 필요 없지만 엔티티의 탐색 속성에 계속 액세스 할 수 있습니다.

var myQuery = from appt in ctx.Appointments 
       where appt.VisitId == visitId 
        && appt.MasterLookup.LookupDescription.ToUpper() != Rescheduled 
        && appt.Site.PracticeID == practiceId 
        && appt.MasterLookup.LookupDescription.ToUpper() != Cancelled 
       orderby appt.AppointmentId descending 
       select new DisplayClass 
       { 
       Property1 = appt.Prop1, 
       Proeprty2 = appt.Visit.Prop1, 
       . 
       . 
       . 
       }; 
+0

다른 옵션이 있습니까? 이를 사용하는 페이지는 약속 및 모든 관련 탐색 속성을 필요로합니다. – Scot

+0

@Scot - 실제로 Appointment 엔터티인지 확인하고 있습니까? 특정 속성 이름에 바인딩하는 경우 DisplayClass 엔티티를 동일한 이름으로 만들 수 있습니다. – Aducci

+0

예, 약속 엔티티 및 관련 하위 개체가 필요합니다. 그게 내가 실행중인 문제입니다. "include"와 함께 실행하는 데 오랜 시간이 걸리는데, include가 없으면 해당 자식 객체에 액세스 할 수 없습니다. – Scot

관련 문제