Compiled queries in EF Core are amazing!

Yesterday I played a bit with compiled queries, I haven’t expected much after reading blogs like this – a modest improvement perhaps. But one of my queries was

context.TableA.Include(a => a.TableB) .ThenInclude(b => b.TableC) .ThenInclude(b => b.TableD) .Include(a => a.TableE) .Include(a => a.TableF) .SingleOrDefault(a => a.ID == id)); 

(just getting lots of details for one entity). I didn’t measure the perf properly, but just stepping thru the code in VS: first run went from 450ms to 200ms and subsequent runs went from 250ms to 25ms.

If you have complicated queries be sure to try it!

submitted by /u/almost_always_lurker
[link] [comments]

Leave a Reply