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
Post a Comment