我有一個問題,讓linq到實體執行良好。我有的查詢(不是我的,維護某人的代碼:-))有幾個包括我已經確定的WPF屏幕都需要使用此查詢的結果。Linq到許多列的實體性能問題
現在,生成的SQL執行速度非常快,只返回一行數據。但它正在返回570列,並且我認爲性能受到創造所有對象和所有這些領域的開銷。
我試過使用延遲加載,但似乎沒有任何影響性能。
我嘗試刪除任何不必要的「包含」語句,但似乎它們都是需要的。
這裏的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生成是4000線長與選擇statment 570列和3或4聯承滴盤,所以我不打算將其粘貼在這裏,除非有人真的想看看它。基本上,我正在尋找一種可能的方式來擺脫工會,並將列修剪到只需要的部分。
幫助!
:-)
這裏閱讀:http://stackoverflow.com/questions/5521749/how-many-include-i-can-use-on-objectset-in-entityframework-to-retain-performance/5522195#5522195 –
謝謝,這有助於解釋使用的影響。包括。那麼,解決方案是否會使用objectContext.LoadProperty()? – Scot
解決方案是使用多種技術,找到在您的場景中提供最佳性能的解決方案。 –