score:0

Unfortunately, Linq does not have a between operator or equivalent. The best (and possibly) only way to achieve this is in sql.

If you are looking to write complex or optimized queries, it is better to use sql rather than linq. The main advantages for this are:

  • Code can be fully tested in management studio, without having to translate and debug in a second language
  • For legacy purposes, it is generally better to use sql for database access code, as this is more widely known amongst database experts. LINQ is the curse of DBAs who have to manage/support code written by others.

I agree with Gerge Mauer's suggestion to use a stored procedure or ADO.

This might still leave you with the problem of parameter sniffing, in which case you may have to use query hints such as OPTIMIZE FOR / RECOMPILE, or local variables to get around this, as demonstrated in this article:

http://blogs.msdn.com/b/turgays/archive/2013/09/10/parameter-sniffing-problem-and-workarounds.aspx


Related Articles