📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

Why can wrapping a column in a function in an EF Core query, such as ToLower() or .Year, make it slow even though it translates?

Intermediate Theory Intermediate

🎯 Key points

  • Function on the column makes the predicate non-sargable
  • Index seek becomes a scan: cost grows with table size
  • Date ranges (>= start AND < end) instead of date parts
  • Case-insensitive collation removes the need for ToLower
  • Persisted computed column with an index

⏱ 30-second answer

Because the generated SQL applies the function to every row (LOWER([c].[Email]) = @email, DATEPART(year, [o].[PlacedAt]) = 2026), so SQL Server can't seek an index on the raw column. It scans the whole index instead, which costs CPU and reads proportional to the table and gets worse as data grows. Fixes: express dates as a half-open range (WHERE [o].[PlacedAt] >= @start AND [o].[PlacedAt] < @end); rely on the database's case-insensitive collation instead of ToLower(), so no function is needed at all; or index a persisted computed column when you really need the derived value.

🔍 What the interviewer is checking

Checks understanding of sargability from the EF Core side.

↩ Usually asked after

More in Querying

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me