c# - EF Materialization is slow with complex Where Query -


i have following query:

context.tblbeauftposmitarbs     .where(bpm => bpm.tblbeauftragungposition.tblbeauftragung.tblprojekt.tbltasks.any(t => t.tblzeitens.any(z => z.datum >= start &&         z.datum <= end &&         employeeids.contains(z.mitarbeiterid))) ||         bpm.tblbeauftragungposition.tblbeauftragung.tblprojekt.tblzeitens.any(z => z.datum >= start &&         z.datum <= end &&         employeeids.contains(z.mitarbeiterid)))     .tolist(); 
  • it returns 700 rows.
  • this takes 24s in linqpad execute.
  • i'm using ef 6.1 database first.
  • the sql generation instant.
  • i tested query in sql management studio , takes less 1 second execute.

i'm using

context.configuration.autodetectchangesenabled = false; context.configuration.proxycreationenabled = false;  
  • asnotracking() has no influence.
  • take(1) has no influence.

simplifying where (although no longer supposed then) cuts execution time in half (about 12s)

context.tblbeauftposmitarbs     .where(bpm => bpm.tblbeauftragungposition.tblbeauftragung.tblprojekt.tbltasks.any(t => t.tblzeitens.any(z => z.datum >= start &&         z.datum <= end &&         employeeids.contains(z.mitarbeiterid))))     .tolist(); 

so guess ef needs more time materialization when complex where statement involved, have no idea why, because where should have impact in sql geeneration , execution time on sql server, not on object materialization.

edit

here code entity class. pk (beauftragungid, beauftposnr)

public partial class tblbeauftposmitarb {     public int beauftragungid { get; set; }     public int beauftposnr { get; set; }     public int maid { get; set; }     public system.datetime timestamp { get; set; }     public nullable<int> einheitid { get; set; }     public nullable<double> menge { get; set; }     public nullable<int> preisgruppeid { get; set; }     public nullable<double> nettopreisproeinheit { get; set; }      public virtual tblbeauftragungposition tblbeauftragungposition { get; set; }     public virtual tblmitarbeiter tblmitarbeiter { get; set; }     public virtual tblpositionstyp tblpositionstyp { get; set; }     public virtual tblprojektpreisgruppe tblprojektpreisgruppe { get; set; } } 

i tried following without effect on execution time:

context.tblbeauftposmitarbs     .where(bpm => bpm.tblbeauftragungposition.tblbeauftragung.tblprojekt.tbltasks.any(t => t.tblzeitens.any(z => z.datum >= start &&         z.datum <= end &&         employeeids.contains(z.mitarbeiterid))) ||         bpm.tblbeauftragungposition.tblbeauftragung.tblprojekt.tblzeitens.any(z => z.datum >= start &&         z.datum <= end &&         employeeids.contains(z.mitarbeiterid)))     .select(bpm => bpm.beauftragungid)     .tolist(); 


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -