Hjelle.Dev
Posts tagged with #entity-framework

Entity framework gotcha you didn’t know about
09 May 2025
Performance issue encountered with Entity Framework Core where a query using FirstOrDefaultAsync and multiple Include statements was unexpectedly slow. By simply moving the filter condition .Where(d => d.Id == doc.Id) earlier in the query chain, EF generated a much more efficient SQL plan, reducing execution time from 20 seconds to milliseconds. The key lesson is that EF sometimes needs a bit of guidance to optimize queries effectively.