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

📚 Interview question

EF Core throws 'The LINQ expression could not be translated'. How do you fix it without moving the whole query to memory?

Junior Theory Beginner

🎯 Key points

  • Read the failing sub-expression in the message
  • Simplify: plain operators and ranges translate best
  • Use EF.Functions, mapped methods or HasDbFunction
  • Computed columns for reusable derived values
  • Client code only in the final Select; anything after AsEnumerable() runs in memory, so filter in SQL first
  • Verify the generated SQL with ToQueryString()

⏱ 30-second answer

Read the message: it names the sub-expression EF Core couldn't translate (usually a C# method, an unmapped property or a complex string operation). Then rewrite that part in SQL-compatible terms: simpler LINQ with plain operators and ranges, EF.Functions.Like, built-in mapped methods, a mapped computed column, or a database function mapped with HasDbFunction. Since EF Core 3.0, client code is allowed only in the final Select; anything you place after AsEnumerable() also runs in memory, so do that only after the filters have run in SQL. Confirm the fix with ToQueryString().

🔍 What the interviewer is checking

Checks the candidate rewrites predicates rather than hiding translation failures.

↩ Usually asked after

More in Querying

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me