entity framework - EF 6 .Include() optimization -



entity framework - EF 6 .Include() optimization -

i have big object needs of it's members loaded @ times.

rtrn.list = context.days .include(x => x.inspections.select(y => y.type)) .include(x => x.inspections.select(y => y.subtype)) .include(x => x.inspections.select(y => y.inspector)) .include(x => x.inspections.select(y => y.approver)) .include(x => x.inspections.select(y => y.operatoraddress)) .include(x => x.inspections.select(y => y.unit)) .include(x => x.inspections.select(y => y.recordsaddress)) .include(x => x.inspections.select(y => y.inspectionaddress)) .include(x => x.inspections.select(y => y.people)) .include(x => x.inspections.select(y => y.customfields)) .include(x => x.inspections.select(y => y.codelinks.select(s => s.codesections.select(q => q.questions.select(a => a.answer))))) .include(x => x.inspections.select(y => y.attachments)) .include(x => x.inspections.select(y => y.comments)) .include(x => x.inspections.select(y => y.compliancerecords.select(z => z.records))) .include(x => x.inspections.select(y => y.correspondencerecords)) .where(x => x.inspector.id == userid).orderbydescending(x => x.daydate).skip(page * perpage).take(perpage).tolist();

it takes time load , looking ideas how speed up. through research have seen suggestion of using .load() method instead of includes tried

var rtrn = context.days..where(x => x.inspector.id == userid).orderbydescending(x => x.daydate).skip(page * perpage).take(perpage).tolist(); foreach (day d in rtrn) { context.entry(d).collection(x => x.inspections).load(); foreach (inspection insp in d.inspections) { context.entry(insp).reference(x => x.type).load(); context.entry(insp).reference(x => x.subtype).load(); context.entry(insp).reference(x => x.inspector).load(); context.entry(insp).reference(x => x.approver).load(); context.entry(insp).reference(x => x.operatoraddress).load(); context.entry(insp).reference(x => x.unit).load(); context.entry(insp).reference(x => x.recordsaddress).load(); context.entry(insp).reference(x => x.inspectionaddress).load(); context.entry(insp).collection(x => x.people).load(); context.entry(insp).collection(x => x.customfields).load(); context.entry(insp).collection(x => x.codelinks).load(); context.entry(insp).collection(x => x.attachments).load(); context.entry(insp).collection(x => x.comments).load(); context.entry(insp).collection(x => x.compliancerecords).load(); context.entry(insp).collection(x => x.correspondencerecords).load(); foreach (codelink cl in insp.codelinks) { context.entry(cl).collection(x => x.codesections).load(); foreach (codesection cs in cl.codesections) { context.entry(cs).collection(x => x.questions).load(); foreach (question q in cs.questions) context.entry(q).reference(x => x.answer).load(); } } foreach (compliancerecordbucket b in insp.compliancerecords) context.entry(b).collection(x => x.records).load(); } }

that takes 10 times longer based on measurements. can't surprised leaves me not knowing tackle this.

entity-framework entity-framework-6

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -