Curious slowness of EF vs SQL Curious slowness of EF vs SQL multithreading multithreading

Curious slowness of EF vs SQL


Can you try as shown below and see whether is there any performance improvement or not ...

Context.MyEntity.AsNoTracking()  .Any(se => se.SameEntity.Field == someValue             && se.AnotherEntity.Field == anotherValue     && se.SimpleField == simpleValue    );


Check if you are reusing the context in a loop. Doing so may create many objects during your performance test and giving the garbage collector a lot of work to do.


Faulty initial assumptions. The SQL in the question was obtained by pasting the code into LINQPad and having it generate the SQL.

After attaching an SQL profiler to the actual DB used, it showed a slightly different SQL involving outer joins, which are suboptimal and didn't have a proper index in place.

It remains a mystery why LINQPad generated different SQL, even though it's using the same EntityFramework.dll, but the original problem is resolved and all that remains is to optimize the query.

Many thanks for everyone involved.